/*
*XMLJavaParser.fx
*
*Created on Apr 3, 2011, 16:35:41 PM
*/

package mythesis.controller;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
import java.lang.*;
import mythesis.tiles.character.*;
import mythesis.tiles.variable.*;
import javafx.scene.*;

var fileNumInteger:Integer = 0;

var codeAI:String = "";				// The complete code
var codeEvents:String[] = [];		// Array of codes, split by events.
// 0 - GameStarted
// 1 - DecidingOnMovement
// 2 - MakingASuggestionOrAccusation
// 3 - ListeningToSuggestion
// 4 - DisprovingSuggestion

//    var didListen = false;		// if true, insert the disproved variables for finalizeAI()

// Code arrays per event
var codeGameStarted:String[] = [];
var codeDecidingOnMovement:String[] = [];
var codeMakingASuggestionOrAccusation:String[] = [];
var codeListeningToSuggestion:String[] = [];
var codeDisprovingSuggestion:String[] = [];

var eventName:String = "GameStarted";
var eventList:String[] = [
							"GameStarted",
							"DecidingOnMovement",
							"MakingASuggestionOrAccusation",
 							"ListeningToSuggestion",
    						"DisprovingSuggestion"
    	      		     ];

public class XMLJavaParser {
};

public function testFunc():Void
{
    var s:String[] = [];
}

// empties AI code
public function newAICode(e:String):Void
{
    eventName  = e;
	codeEvents = [];
	codeAI     = "";
	codeGameStarted = [];
	for (i in [0..500])
	{
	    codeGameStarted[i] = "";
		codeDecidingOnMovement[i] = "";
		codeMakingASuggestionOrAccusation[i] = "";
		codeListeningToSuggestion[i] = "";
		codeDisprovingSuggestion[i] = "";
	}
}

function getElementIndexByName():Integer
{
    if (eventName == "GameStarted")							{	return 0;	}
    else if (eventName == "DecidingOnMovement") 			{	return 1;	}
    else if (eventName == "MakingASuggestionOrAccusation")	{	return 2;	}
    else if (eventName == "ListeningToSuggestion")			{	return 3;	}
    else if (eventName == "DisprovingSuggestion") 			{	return 4;	}
    else													{   println("[XMLTileParser] Unknown event name:  {eventName}"); return 5;	}
}

function addCode(eventID:Number, lineNumber:Integer, tileType:String, argText:String[], argDtype:String[], argDvalue:String[])
{
    /*
    dtype:
      4.0 = special
      3.0 = truth
      2.0 = word
      1.0 = number
    
    dvalue
      1.0 = constant
      2.0 = variable
      3.0 = special
    
    */
    
    if (tileType=="RollDice")
    {
        var toParse:String = "";
        toParse = "{toParse}   if(!hasRolledDice)\{\n";
        toParse = "{toParse}      allowedMoves = rollDice();\n";
        toParse = "{toParse}      hasRolledDice = true;\n";
        toParse = "{toParse}   \}\n";
	 	codeDecidingOnMovement[lineNumber] = toParse;
    }
	if (tileType=="GoTo")
    {
        var toParse:String = "";
        toParse = "{toParse}   if (!hasUsedGoToRoom)\{\n";
        /*
      *<Word>   getNearestRoom()            -- name of nearest room
      *<Word>   getNearestInnoRoom()        -- name of nearest room that isn't disproved
      *<Word>   getNearestForeignInnoRoom() -- name of nearest room that isn't disproved AND I'm not inside in
        */
        if (argText[0].contains("()"))
        {
            toParse = "{toParse}      walkToRoom({argText[0]});\n";
        }
        else
        {
        	toParse = "{toParse}      walkToRoom(\"{argText[0]}\");\n";
        }
        toParse = "{toParse}      hasUsedGoToRoom = true;\n";
        toParse = "{toParse}   \}";
	    codeDecidingOnMovement[lineNumber]            = toParse;
    }
	else if (tileType=="Suggest")
    {
        var toParse:String = "";
        toParse = "{toParse}   if (!hasSuggested)\{\n";
        toParse = "{toParse}      if (me.canSuggestHere() == true && me.canSuggest() == true)\{\n";
        toParse = "{toParse}         suggest({argText[0]}, {argText[1]});\n";
        toParse = "{toParse}         hasSuggested = true;\n";
        toParse = "{toParse}      \}\n\n";
        toParse = "{toParse}   \}\n\n";
        codeMakingASuggestionOrAccusation[lineNumber] = toParse;
    }
   
	else if (tileType=="Accuse")
    {
        var toParse:String = "";
        toParse = "{toParse}   if (!hasAccused)\{\n";
        toParse = "{toParse}      boolean result = accuse({argText[0]}, {argText[1]}, {argText[2]});\n";
        toParse = "{toParse}      if(result == false)\{\n";
        toParse = "{toParse}         outputMessage(\"I LOST the game, I made a wrong accusation.\");\n";
        toParse = "{toParse}         hasMadeFalseAccusation = true;\n";
        toParse = "{toParse}      \}\n";
        toParse = "{toParse}      else\{\n";
        toParse = "{toParse}         outputMessage(\"I WON the game.\");\n";
        toParse = "{toParse}         Vector parameters = new Vector();\n";
        toParse = "{toParse}         parameters.add(me);\n";
        toParse = "{toParse}         gameController.directCommand(\"winGame\", parameters);\n";
        toParse = "{toParse}      \}\n\n";
        toParse = "{toParse}      hasAccused = true;\n";
        toParse = "{toParse}   \}";
		//codeMakingASuggestionOrAccusation[lineNumber] = "   accuse({argText[0]}, {argText[1]}, {argText[2]});\n";
		codeMakingASuggestionOrAccusation[lineNumber] = toParse;
    }
	else if (tileType=="ListenToSuggestion")
    {
        var toParse:String = "";
        toParse = "{toParse}   if (!hasListened)\{\n";
        toParse = "{toParse}      hasListened= true;\n";
	    toParse = "{toParse}      suggester = d.getDisprovedBy();\n";
        toParse = "{toParse}      disprover = d.getOriginalSuggestion().suggestedBy;\n";
	    toParse = "{toParse}      suggestedSuspect = d.getOriginalSuggestion().getWho().getName();\n";
	    toParse = "{toParse}      suggestedWeapon = d.getOriginalSuggestion().getWhat().getName();\n";
	    toParse = "{toParse}      suggestedRoom = d.getOriginalSuggestion().getWhere().getName();\n";
        toParse = "{toParse}      if (!disprover.equals(\"\")) disproved = true;\n";
        toParse = "{toParse}      else disproved = false;\n";
	    toParse = "{toParse}      outputMessage(\"Listening... \" +suggester+ \" suggested \" +suggestedSuspect+ \", \" +suggestedWeapon+ \" and \" +suggestedRoom+ \".\");\n";
	    toParse = "{toParse}      if (!disprover.equals(\"\"))";
	    toParse = "{toParse}      \{\n";
	    toParse = "{toParse}         outputMessage(\"It was disproved by \" +disprover+ \".\");\n";
	    toParse = "{toParse}      \}\n\n";
	    toParse = "{toParse}      else";
	    toParse = "{toParse}      \{\n";
	    toParse = "{toParse}         outputMessage(\"No one could disprove it.\");\n";
	    toParse = "{toParse}      \}\n\n";
 	    toParse = "{toParse}      suggestedSuspect = \"\";\n";
	    toParse = "{toParse}      suggestedWeapon  = \"\";\n";
	    toParse = "{toParse}      suggestedRoom    = \"\";\n";       
        //toParse = "{toParse}      suggester = d.getDisprovedBy();\n";
        //toParse = "{toParse}      disprover = d.getOriginalSuggestion().suggestedBy;\n";
        //toParse = "{toParse}      if (!disprover.equals(\"\")) disproved = true;\n";
        //toParse = "{toParse}      else disproved = false;\n";

        toParse = "{toParse}   \}\n";
       	codeListeningToSuggestion[lineNumber] = toParse;
    }
    
    else if (tileType=="DisproveSuggestionWith")
    {        
        var suspectWeaponRoom:String =           "   if(me.getCards().containsCard(alert.getWho()))\n";
        suspectWeaponRoom   = "{suspectWeaponRoom}      chosenCard = alert.who.getName();\n";
        suspectWeaponRoom   = "{suspectWeaponRoom}   else if(me.getCards().containsCard(alert.getWhat()))\n";
        suspectWeaponRoom   = "{suspectWeaponRoom}      chosenCard = alert.what.getName();\n";
        suspectWeaponRoom   = "{suspectWeaponRoom}   else if(me.getCards().containsCard(alert.getWhere()))\n";
        suspectWeaponRoom   = "{suspectWeaponRoom}      chosenCard = alert.where.getName();\n\n";
        
		var suspectRoomWeapon:String =           "   if(me.getCards().containsCard(alert.getWho()))\n";
        suspectRoomWeapon   = "{suspectRoomWeapon}      chosenCard = alert.who.getName();\n";
        suspectRoomWeapon   = "{suspectRoomWeapon}   else if(me.getCards().containsCard(alert.getWhere()))\n";
        suspectRoomWeapon   = "{suspectRoomWeapon}      chosenCard = alert.where.getName();\n";
        suspectRoomWeapon   = "{suspectRoomWeapon}   else if(me.getCards().containsCard(alert.getWhat()))\n";
        suspectRoomWeapon   = "{suspectRoomWeapon}      chosenCard = alert.what.getName();\n\n";
        
        var weaponSuspectRoom:String =           "   if(me.getCards().containsCard(alert.getWhat()))\n";
        weaponSuspectRoom   = "{weaponSuspectRoom}      chosenCard = alert.what.getName();\n";
        weaponSuspectRoom   = "{weaponSuspectRoom}   else if(me.getCards().containsCard(alert.getWho()))\n";
        weaponSuspectRoom   = "{weaponSuspectRoom}      chosenCard = alert.who.getName();\n";
        weaponSuspectRoom   = "{weaponSuspectRoom}   else if(me.getCards().containsCard(alert.getWhere()))\n";
        weaponSuspectRoom   = "{weaponSuspectRoom}      chosenCard = alert.where.getName();\n\n";
        
        var weaponRoomSuspect:String =           "   if(me.getCards().containsCard(alert.getWhat()))\n";
        weaponRoomSuspect   = "{weaponRoomSuspect}      chosenCard = alert.what.getName();\n";
        weaponRoomSuspect   = "{weaponRoomSuspect}   else if(me.getCards().containsCard(alert.getWhere()))\n";
        weaponRoomSuspect   = "{weaponRoomSuspect}      chosenCard = alert.where.getName();\n";
        weaponRoomSuspect   = "{weaponRoomSuspect}   else if(me.getCards().containsCard(alert.getWho()))\n";
        weaponRoomSuspect   = "{weaponRoomSuspect}      chosenCard = alert.who.getName();\n\n";
        
        var roomWeaponSuspect:String =            "  if(me.getCards().containsCard(alert.getWhere()))\n";
        roomWeaponSuspect   = "{roomWeaponSuspect}      chosenCard = alert.where.getName();\n";
        roomWeaponSuspect   = "{roomWeaponSuspect}   else if(me.getCards().containsCard(alert.getWhat()))\n";
        roomWeaponSuspect   = "{roomWeaponSuspect}      chosenCard = alert.what.getName();\n";
        roomWeaponSuspect   = "{roomWeaponSuspect}   else if(me.getCards().containsCard(alert.getWho()))\n";
        roomWeaponSuspect   = "{roomWeaponSuspect}      chosenCard = alert.who.getName();\n\n";
        
        var roomSuspectWeapon:String =            "  if(me.getCards().containsCard(alert.getWhere()))\n";
        roomSuspectWeapon   = "{roomSuspectWeapon}      chosenCard = alert.where.getName();\n";
        roomSuspectWeapon   = "{roomSuspectWeapon}   else if(me.getCards().containsCard(alert.getWho()))\n";
        roomSuspectWeapon   = "{roomSuspectWeapon}      chosenCard = alert.who.getName();\n";
        roomSuspectWeapon   = "{roomSuspectWeapon}   else if(me.getCards().containsCard(alert.getWhat()))\n";
        roomSuspectWeapon   = "{roomSuspectWeapon}      chosenCard = alert.what.getName();\n\n";

        var toParse:String  = "";
        if (argText[0]      == "suspect, weapon then room"){ toParse = suspectWeaponRoom; }
        else if (argText[0] == "suspect, room then weapon"){ toParse = suspectRoomWeapon; }
    	else if (argText[0] == "weapon, suspect then room"){ toParse = weaponSuspectRoom; }
    	else if (argText[0] == "weapon, room then suspect"){ toParse = weaponRoomSuspect; }
    	else if (argText[0] == "room, weapon then suspect"){ toParse = roomWeaponSuspect; }
    	else if (argText[0] == "room, suspect then weapon"){ toParse = roomSuspectWeapon; }
    	
    	var toParseWithCheck:String = "";
    	toParseWithCheck = "{toParseWithCheck}   if(!hasDisproved)\{\n";
    	toParseWithCheck = "{toParseWithCheck}{toParse}";
	    toParse          = "{toParseWithCheck}      suggestedSuspect = \"\";\n";
	    toParse          = "{toParseWithCheck}      suggestedWeapon  = \"\";\n";
	    toParse          = "{toParseWithCheck}      suggestedRoom    = \"\";\n";
    	toParseWithCheck = "{toParseWithCheck}      hasDisproved = true;\n";
    	toParseWithCheck = "{toParseWithCheck}   \}\n";
    	codeDisprovingSuggestion[lineNumber] = toParseWithCheck;
    }
    
    
    
    else if (tileType=="Note")
    {
        //println(argDtype);
        if (argText[1] == "Number")
        {
            if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   int {argText[0]} = 0;\n"; }
	        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   int {argText[0]} = 0;\n"; }
        	else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   int {argText[0]} = 0;\n"; }
        	else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   int {argText[0]} = 0;\n"; }
        	else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   int {argText[0]} = 0;\n"; }
        }
        else if (argText[1] == "Word")
        {
            if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   String {argText[0]} = \"\";\n"; }
	        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   String {argText[0]} = \"\";\n"; }
        	else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   String {argText[0]} = \"\";\n"; }
        	else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   String {argText[0]} = \"\";\n"; }
        	else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   String {argText[0]} = \"\";\n"; }
        }
        else if (argText[1] == "Truth")
        {
            if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   boolean {argText[0]} = false;\n"; }
	        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   boolean {argText[0]} = false;\n"; }
        	else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   boolean {argText[0]} = false;\n"; }
        	else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   boolean {argText[0]} = false;\n"; }
        	else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   boolean {argText[0]} = false;\n"; }
        }
    }
    else if (tileType=="Set")
    {
        
        if (argDtype[0] == "1.0" or argDtype[0] == "3.0")
        {
            if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   {argText[0]} = {argText[1]};\n"; }
	        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   {argText[0]} = {argText[1]};\n"; }
        	else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   {argText[0]} = {argText[1]};\n"; }
        	else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   {argText[0]} = {argText[1]};\n"; }
        	else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   {argText[0]} = {argText[1]};\n"; }
        }
        else if (argDtype[0] == "2.0")
        {
            var setValue:String = "ERRORSETVALUE";
            if (argDvalue[1] == "1.0"){ setValue = "\"{argText[1]}\""; }
            else{                       setValue = "{argText[1]}";     }
            if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   {argText[0]} = {setValue};\n"; }
	        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   {argText[0]} = {setValue};\n"; }
        	else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   {argText[0]} = {setValue};\n"; }
        	else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   {argText[0]} = {setValue};\n"; }
        	else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   {argText[0]} = {setValue};\n"; }
        }
    }
    else if (tileType=="Increase")
    {
        if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   {argText[0]} += {argText[1]};\n"; }
        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   {argText[0]} += {argText[1]};\n"; }
        else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   {argText[0]} += {argText[1]};\n"; }
        else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   {argText[0]} += {argText[1]};\n"; }
        else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   {argText[0]} += {argText[1]};\n"; }
    }
    else if (tileType=="Decrease")
    {
        if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   {argText[0]} -= {argText[1]};\n"; }
        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   {argText[0]} -= {argText[1]};\n"; }
        else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   {argText[0]} -= {argText[1]};\n"; }
        else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   {argText[0]} -= {argText[1]};\n"; }
        else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   {argText[0]} -= {argText[1]};\n"; }
    }
    else if (tileType=="Multiply")
    {
        //println(" wat {eventID}");
        if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   {argText[0]} *= {argText[1]};\n"; }
        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   {argText[0]} *= {argText[1]};\n"; }
        else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   {argText[0]} *= {argText[1]};\n"; }
        else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   {argText[0]} *= {argText[1]};\n"; }
        else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   {argText[0]} *= {argText[1]};\n"; }
    }
    else if (tileType=="Divide")
    {
        var toParse:String = "";
        var equalizer:String = "";
        if (argDvalue[1]=="1.0" or argDvalue[1]=="1")
        {
            var divisor:Integer = 0;
        	divisor = Integer.parseInt(argText[1]);
        	if (divisor == 0){ divisor = 1; }
        	equalizer = "{divisor}";
        }
        else
        {
            toParse = "{toParse}   if ({argText[1]} == 0)\{  {argText[1]} = 1; \}\n";
            equalizer = "{argText[1]}";
        }
        
        
        toParse = "{toParse}   {argText[0]} /= {equalizer};\n";
        
        if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = toParse; }
        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = toParse; }
        else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = toParse; }
        else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = toParse; }
        else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = toParse; }
    }
    else if (tileType=="Raise")
    {
        if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   {argText[0]} = (int)Math.pow((double){argText[0]}, {argText[1]});\n"; }
        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   {argText[0]} = (int)Math.pow((double){argText[0]}, {argText[1]});\n"; }
        else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   {argText[0]} = (int)Math.pow((double){argText[0]}, {argText[1]});\n"; }
        else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   {argText[0]} = (int)Math.pow((double){argText[0]}, {argText[1]});\n"; }
        else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   {argText[0]} = (int)Math.pow((double){argText[0]}, {argText[1]});\n"; }
    }
    else if (tileType=="Testify")
    {
        if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   {argText[0]} = true;\n"; }
        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   {argText[0]} = true;\n"; }
        else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   {argText[0]} = true;\n"; }
        else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   {argText[0]} = true;\n"; }
        else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   {argText[0]} = true;\n"; }
    }
    else if (tileType=="Falsify")
    {
        if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   {argText[0]} = false;\n"; }
        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   {argText[0]} = false;\n"; }
        else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   {argText[0]} = false;\n"; }
        else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   {argText[0]} = false;\n"; }
        else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   {argText[0]} = false;\n"; }
    }
    else if (tileType=="EndCondition")
    {
        if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   \};\n\n"; }
        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   \};\n\n"; }
        else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   \};\n\n"; }
        else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   \};\n\n"; }
        else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   \};\n\n"; }
    }
    else if (tileType=="BreakCondition")
    {
        if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   break;\n"; }
        else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   break;\n"; }
        else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   break;\n"; }
        else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   break;\n"; }
        else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   break;\n"; }
    }
    else if (tileType=="If")
    {
        if (argDtype[0] == "1.0" or argDtype[0] == "3.0")
        {
            if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "\n   if ({argText[0]} {argText[1]} {argText[2]})\n   \{\n"; }
			else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "\n   if ({argText[0]} {argText[1]} {argText[2]})\n   \{\n"; }
        	else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "\n   if ({argText[0]} {argText[1]} {argText[2]})\n   \{\n"; }
        	else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "\n   if ({argText[0]} {argText[1]} {argText[2]})\n   \{\n"; }
        	else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "\n   if ({argText[0]} {argText[1]} {argText[2]})\n   \{\n"; }
        }
        else if (argDtype[0] == "2.0")
        {
            var setValue:String = "ERRORSETVALUE";
            if (argDvalue[2] == "1.0"){ setValue = "\"{argText[2]}\""; }
            else{                       setValue = "{argText[2]}";     }
            
            if (argText[1] == "==")
            {
	            if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "\n   if ({argText[0]}.equals({setValue}))\n   \{\n"; }
				else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "\n   if ({argText[0]}.equals({setValue}))\n   \{\n"; }
	        	else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "\n   if ({argText[0]}.equals({setValue}))\n   \{\n"; }
	        	else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "\n   if ({argText[0]}.equals({setValue}))\n   \{\n"; }
	        	else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "\n   if ({argText[0]}.equals({setValue}))\n   \{\n"; }
            }
            else if (argText[1] == "!=")
            {
	            if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "\n   if (!{argText[0]}.equals({setValue}))\n   \{\n"; }
				else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "\n   if (!{argText[0]}.equals({setValue}))\n   \{\n"; }
	        	else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "\n   if (!{argText[0]}.equals({setValue}))\n   \{\n"; }
	        	else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "\n   if (!{argText[0]}.equals({setValue}))\n   \{\n"; }
	        	else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "\n   if (!{argText[0]}.equals({setValue}))\n   \{\n"; }
            }
            

            //if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "   if ({argText[0]} {argText[1]} {setValue})\n   \{\n"; }
			//else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "   if ({argText[0]} {argText[1]} {setValue})\n   \{\n"; }
        	//else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "   if ({argText[0]} {argText[1]} {setValue})\n   \{\n"; }
        	//else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "   if ({argText[0]} {argText[1]} {setValue})\n   \{\n"; }
        	//else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "   if ({argText[0]} {argText[1]} {setValue})\n   \{\n"; }
        }
    }
    else if (tileType=="While")
    {
        if (argDtype[0] == "1.0" or argDtype[0] == "3.0")
        {
            if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!({argText[0]} {argText[1]} {argText[2]}))\{break;\}\n"; }
			else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!({argText[0]} {argText[1]} {argText[2]}))\{break;\}\n"; }
        	else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!({argText[0]} {argText[1]} {argText[2]}))\{break;\}\n"; }
        	else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!({argText[0]} {argText[1]} {argText[2]}))\{break;\}\n"; }
        	else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!({argText[0]} {argText[1]} {argText[2]}))\{break;\}\n"; }
        }
        else if (argDtype[0] == "2.0")
        {
            var setValue:String = "ERRORSETVALUE";
            if (argDvalue[2] == "1.0"){ setValue = "\"{argText[2]}\""; }
            else{                       setValue = "{argText[2]}";     }
            
            if (argText[1] == "==")
            {
	            if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!({argText[0]}.equals({setValue})))\{break;\}\n"; }
				else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!({argText[0]}.equals({setValue})))\{break;\}\n"; }
	        	else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!({argText[0]}.equals({setValue})))\{break;\}\n"; }
	        	else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!({argText[0]}.equals({setValue})))\{break;\}\n"; }
	        	else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!({argText[0]}.equals({setValue})))\{break;\}\n"; }
            }
            else if (argText[1] == "!=")
            {
	            if (eventID==0 or eventID ==0.0){      codeGameStarted[lineNumber]                   = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!(!{argText[0]}.equals({setValue})))\{break;\}\n"; }
				else if (eventID==1 or eventID ==1.0){ codeDecidingOnMovement[lineNumber]            = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!(!{argText[0]}.equals({setValue})))\{break;\}\n"; }
	        	else if (eventID==2 or eventID ==2.0){ codeMakingASuggestionOrAccusation[lineNumber] = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!(!{argText[0]}.equals({setValue})))\{break;\}\n"; }
	        	else if (eventID==3 or eventID ==3.0){ codeListeningToSuggestion[lineNumber]         = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!(!{argText[0]}.equals({setValue})))\{break;\}\n"; }
	        	else if (eventID==4 or eventID ==4.0){ codeDisprovingSuggestion[lineNumber]          = "\n   for (int i=0; i<100; i++)\n   \{\n   if(!(!{argText[0]}.equals({setValue})))\{break;\}\n"; }
            }            
        }
    }
}

public function getAICode(fileNumber:Number):String
{
    newAICode("GameStarted");
    // remove decimal point
	var fileNumString:String = fileNumber.toString();
	fileNumString = fileNumString.replace(".0", "");
	fileNumInteger = java.lang.Integer.parseInt(fileNumString);

	for (zzz in [0..eventList.size()-1])
	{
	    eventName = eventList[zzz];
	    var dbf:DocumentBuilderFactory = DocumentBuilderFactory.newInstance();
	    try
	    {
	        var db:DocumentBuilder = dbf.newDocumentBuilder();
	        var doc:Document = db.parse(new FileInputStream("CustomAI{fileNumInteger}.xml"));
	        
	        var root:Element = doc.getDocumentElement();
	        var events = root.getElementsByTagName("event");
	        var id = getElementIndexByName();
	        
	        // get particular event only
	        var el:Element  = {events.item(id) as Element};
	        var type:String = el.getAttribute("type");
	        //println(" Event name: {type}");
	        
	        // get all tiles
	        var tiles:NodeList = el.getElementsByTagName("tile");
	        //println(" # of tiles: {tiles.getLength()}");
	        
	        // loop through all tiles
	        for (j in [0..tiles.getLength()-1])
	        {
	            var ti:Element = {tiles.item(j) as Element};
	            // get name and line
	            var tileType:String     = ti.getAttribute("type");
	            var lineNumber:String   = ti.getAttribute("line");
	            var argList:NodeList    = ti.getElementsByTagName("arg");
	            lineNumber = lineNumber.replace(".0", "");
	            var lineNumberInteger:Integer = java.lang.Integer.parseInt(lineNumber);
	            var lineNumberNumber:Number = {lineNumberInteger as Number};
	            
	            var arrArgText:String[]   = [];
	            var arrArgDtype:String[]  = [];
	            var arrArgDvalue:String[] = [];
	            
	            //print(" > line:{lineNumber} :: {tileType} ");
	            for (k in [0..argList.getLength()-1])
	            {
	                var arg:Element      = {argList.item(k) as Element};
	                var argText:String   = arg.getTextContent();
	                var argDtype:String  = arg.getAttribute("dtype");
	                var argDvalue:String = arg.getAttribute("dvalue");
	                
	                insert argText into arrArgText;
	                insert argDtype into arrArgDtype;
	                insert argDvalue into arrArgDvalue;
	                
	                //print(" [{argDtype}][{argDvalue}]({argText}) ");
	            }
	            // Considering the tile type plus array of data types, argTexts...
	            addCode(id, lineNumberNumber, tileType, arrArgText, arrArgDtype, arrArgDvalue);
	            //println("\n");
	            
	        }
	    }
	    catch (e:NumberFormatException)
	    {
	        println("[XMLJavaParser.getAICode()] {eventName} {e}");
	    }
    }
 
 	finalizeAICode(fileNumInteger);
 	//println("size : {codeAI.length()}");   
    //println(codeAI);
    
    return codeAI;
}

function finalizeAICode(fileNumInteger:Integer)
{	
    var asdf:String = "";
    var codeEvent1:String = "";
    var codeEvent2:String = "";
    var codeEvent3:String = "";
    var codeEvent4:String = "";
    var codeEvent5:String = "";
    var code1:String = "package Cluedo.AI;\nimport Cluedo.API.*;\nimport Cluedo.Game.*;\nimport Cluedo.Controller.*;\nimport java.text.SimpleDateFormat;\nimport java.util.Calendar;\nimport java.util.Vector;\nimport java.util.StringTokenizer;\nimport java.io.BufferedWriter;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.lang.StringBuffer;\npublic class CustomAI{fileNumInteger} implements    Runnable, Cluedo.API.AIContract \{\n   String DATE_FORMAT_NOW = \"yyyyMMddHHmmss\";\n      Calendar cal = Calendar.getInstance();\n   SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);\n   String calFileName = sdf.format(cal.getTime());\n   static int sleepPeriod = 200;\n   String myName = \"\";\n   boolean dead = false;\n   boolean hasMadeFalseAccusation = false;\n   Vector inbox = new Vector();\n   String motive = \"\";\n   Position destination = null;\n   boolean disproofReceived = true;\n   Message incomingDisproof = null;\n   String [] motives = \{ \"findRoom\", \"walkToRoom\",\};\n   private String screenOutput = \"\";\n   boolean hasRolledDice = false;\n   boolean hasSuggested = false;\n   boolean hasAccused = false;\n   boolean hasListened = false;\n   boolean hasDisproved = false;\n   boolean hasUsedGoToRoom = false;\n   String disprover = \"\";\n   String suggester = \"\";\n   String disproofCard = \"\";\n    String disproofPerson = \"\";\n   String suggestedSuspect = \"\";\n   String suggestedWeapon = \"\";\n   String suggestedRoom = \"\";\n   int allowedMoves = 0;\n   String card1 = \"\";\n   String card2 = \"\";\n   String card3 = \"\";\n   String card4 = \"\";\n   String card5 = \"\";\n   String card6 = \"\";\n   boolean hasCheckedMyCards = false;\n   String MrsWhite = \"MrsWhite\";\n   String MissScarlett = \"MissScarlett\";\n   String ReverendGreen = \"ReverendGreen\";\n   String ColonelMustard = \"ColonelMustard\";\n   String MrsPeacock = \"MrsPeacock\";\n   String ProfessorPlum = \"ProfessorPlum\";\n   String Rope = \"Rope\";\n   String Dagger = \"Dagger\";\n   String Spanner = \"Spanner\";\n   String Revolver = \"Revolver\";\n   String LeadPipe = \"LeadPipe\";\n   String Candlestick = \"Candlestick\";\n   String Hall = \"Hall\";\n   String Conservatory = \"Conservatory\";\n   String Study = \"Study\";\n   String BilliardRoom = \"BilliardRoom\";\n   String Library = \"Library\";\n   String Ballroom = \"Ballroom\";\n   String Lounge = \"Lounge\";\n   String Kitchen = \"Kitchen\";\n   String DiningRoom = \"DiningRoom\";\n   boolean dpHall = false;\n   boolean dpConservatory = false;\n   boolean dpStudy = false;\n   boolean dpBilliardRoom = false;\n   boolean dpLibrary = false;\n   boolean dpBallroom = false;\n   boolean dpLounge = false;\n   boolean dpKitchen = false;\n   boolean dpDiningRoom = false;\n   boolean dpMrsWhite = false;\n   boolean dpMissScarlett = false;\n   boolean dpReverendGreen = false;\n   boolean dpColonelMustard = false;\n   boolean dpMrsPeacock = false;\n   boolean dpProfessorPlum = false;\n   boolean dpRope = false;\n   boolean dpDagger = false;\n   boolean dpSpanner = false;\n   boolean dpRevolver = false;\n   boolean dpLeadPipe = false;\n   boolean dpCandlestick = false;\n   private String[] roomNameList = \{\"Kitchen\", \"DiningRoom\", \"Lounge\", \"Ballroom\", \"Hall\", \"Study\", \"Library\", \"BilliardRoom\", \"Conservatory\"\};   boolean disproved = false;\n   private BufferedWriter out;\n";
    var code2:String = "   CluedoListener cluedoListener = new CluedoListener() \{\n      public void localMessage(Cluedo.API.Message message) \{\n\}\n\n      public void notifyAlert(Message message) \{\n         String output = \"\";\n                  if(disproofReceived == false) \{\n            if(message.type.equals(\"disproofAlert\")) \{\n               disproofReceived = true;\n               incomingDisproof = message;\n               inbox.add(message);\n            \}\n\n         \}\n\n         else\{\n            inbox.add(message);\n         \}\n\n      \}\n\n      public CluedoListener getCluedoListener() \{\n         return this;\n      \}\n\n   \}\n\n;\n   public CluedoListener getCluedoListener () \{\n      return cluedoListener;\n   \}\n\n   private void sleepFor(int interval) \{\n      try \{\n         Thread.sleep(interval);\n      \}\n\n      catch (Exception e) \{\n         e.printStackTrace();\n      \}\n\n   \}\n\n   public CustomAI{fileNumInteger} (String args, GameController gameController, String AIName) \{\n      myName = AIName;\n      this.gameController = gameController;\n      outputMessage(\" Hello, my name is \" + myName + \"!\");\n  System.out.println(roomNameList);\n    bindAI();\n      motive = \"findRoom\";\n   \}\n\n   public void bindAI() \{\n      try \{\n         gameController.bindListener(getCluedoListener());\n      \}\n\n      catch(Exception Error) \{\n         System.out.println(\"[CustomAI13:BindAI\" + myName + \"]: can't bind\");\n      \}\n\n   \}\n\n   synchronized public void die() \{\n      dead = true;\n   \}\n\n   public void run () \{\n      while( dead == false ) \{\n         try \{\n            try \{\n               Thread.sleep(100);\n            \}\n\n            catch (InterruptedException e) \{\n               e.printStackTrace();\n            \}\n\n            if(inbox.size() > 0) \{\n               while(inbox.size() > 0) \{\n                  Thread.sleep(10);\n                  handleMessage(((Message)inbox.firstElement()));\n                     inbox.remove(inbox.firstElement());\n               \}\n\n            \}\n\n         \}\n\n         catch (InterruptedException e) \{\n         \}\n\n      \}\n\n   \}\n\n   public void whatAreMyCards()   \{\n      if (hasCheckedMyCards == false)      \{\n         Player me = gameController.getBoard().getPlayer(myName);\n         CardCollection myCards = me.getCards();\n         int myCardCount = me.getCards().getCards().size();\n         for (int i=0; i<myCardCount; i++)         \{\n            outputMessage(myCards.cardAt(i).getName());\n            if(i==0)\{\n card1 = myCards.cardAt(i).getName();\n \}\n\n            if(i==1)\{\n card2 = myCards.cardAt(i).getName();\n \}\n\n            if(i==2)\{\n card3 = myCards.cardAt(i).getName();\n \}\n\n            if(i==3)\{\n card4 = myCards.cardAt(i).getName();\n \}\n\n            if(i==4)\{\n card5 = myCards.cardAt(i).getName();\n \}\n\n            if(i==5)\{\n card6 = myCards.cardAt(i).getName();\n \}\n\n         \}\n\n         outputMessage(\" I have \" + myCardCount + \" cards, which are... \" +card1+ \", \" +card2+ \", \" +card3+ \", \" +card4+ \", \" +card5+ \", \" +card6+ \".\");\n         hasCheckedMyCards = true;\n      \}\n\n   \}\n\n   public void handleMessage(Message message) \{\n      String output = \"\";\n      if(gameController.getBoard().getGameFinished() == false) \{\n         if(message.type.equals(\"newRoll\")) \{\n                            \}\n\n         if(message.type.equals(\"commenceGame\")) \{\n            message.type = \"nextPlayer\";\n            sleepFor(4000);\n         \}\n\n         else if(message.type.equals(\"newEnvelope\")) \{\n         \}\n\n         else if(message.type.equals(\"suggestionAlert\")) \{\n            if(message.data.equals(myName)) \{\n               handleSuggestionAlert(message);\n            \}\n\n         \}\n\n         else if(message.type.equals(\"disproofAlert\")) \{\n               outputMessage(\"Aha!  Did someone just try to disprove?\");\n               if(disproofReceived == false) \{\n                  DisproofAlert d = ((DisproofAlert)message.parameters.get(0));\n                  deductFromDisproof(d);\n               \}\n\n               disproofReceived = true;\n         \}\n\n         else if(message.type.equals(\"nextPlayer\")) \{\n            whatAreMyCards();\n            if(gameController.getBoard().getCurrentPlayer().getRealName().equals(myName)) \{\n               takeTurn();\n            \}\n\n         \}\n\n         else if(message.type.equals(\"moveAlert\")) \{\n         \}\n\n      \}\n\n      else \{\n         if(dead == false) \{\n            outputMessage(\"Game is over.  I'm quitting.\");\n            die();\n         \}\n\n      \}\n\n      if(!output.equals(\"\"))\{\n         outputMessage(output);\n      \}\n\n   \}\n\n   private boolean isEliminated(String name) \{\n      Player me = gameController.getBoard().getCurrentPlayer();\n      return me.getDetectivePad().getCardList().cardByName(name).isEliminated();\n   \}\n\n   public void setMyName(String myName) \{\n      this.myName = myName;\n   \}\n\n   public void initaliseAI() \{\n      System.out.println(\"[CustomAI{fileNumInteger} \" + myName + \"]: Initalised \"+myName+\".\");\n   \}\n\n   GameController gameController = null;\n   Cluedo.GUI.TextParser textParser;\n   Cluedo.GUI.TextEventHandler textHandler = new Cluedo.GUI.TextEventHandler(this);\n   CluedoConfig gameConfig = null;\n   int debugLevel = 0;\n   synchronized void outputMessage(String output ) \{\n      try \{\n         out = new BufferedWriter(new FileWriter(\"log\" + myName + \"-\" + sdf.format(cal.getTime()) + \".txt\", true));\n         out.write(\"[CustomAI1 \" + myName + \"]: \" +output + \"\\n\");\n         out.newLine();\n         out.close();\n      \}\n\n      catch (Exception e)\{\n         System.out.println(\"Exception \" + e);\n      \}\n\n   \}\n\n   synchronized public String endGo() \{\n      outputMessage(\"My turn is over.\");\n      gameController.directCommand(\"nextPlayer\", null);\n      return \"\";\n   \}\n\n   synchronized public String buildCards() \{\n      StringBuffer buffer = new StringBuffer();\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getCards();\n      CardCollection myDCards = me.getDetectivePad().getCardList();\n      for(int i = 0; i < myDCards.countCards(); i++) \{\n         buffer.append(\"- \" + myDCards.cardAt(i).getName() +\"\t\" + myDCards.cardAt(i).isEliminated()+\"\\n\");\n      \}\n\n      return buffer.toString();\n   \}\n\n";
    var code3:String = "   synchronized public void takeTurn() \{\n      outputMessage(\"\\n\\nI will now take my turn.\");\n      outputMessage(\" DEBUG: \" + guiltySusp + \" suspects, \" + guiltyWeap + \" weapons and \" + guiltyRoom + \" rooms.\");\n     sleepFor(sleepPeriod);\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getCards();\n      CardCollection myDCards = me.getDetectivePad().getCardList();\n      sleepFor(sleepPeriod);\n      if (hasMadeFalseAccusation == false) runDecideOnMovementEvent();\n      sleepFor(sleepPeriod);\n      if (hasMadeFalseAccusation == false) runSuggestOrAccuseEvent();\n      hasRolledDice=false;\n      hasSuggested=false;\n      hasAccused=false;\n      hasListened=false;\n      hasDisproved=false;\n      hasUsedGoToRoom=false;\n      suggester = \"\";\n      disprover = \"\";\n      disproved = false;\n      allowedMoves = 0;\n      suggestedSuspect = \"\";\n      suggestedWeapon  = \"\";\n      suggestedRoom    = \"\";\n      disproofCard     = \"\";\n      disproofPerson   = \"\";\n            endGo();\n   \}\n\n";
    var code4:String = "   Position findNeighbour(Position node) \{\n      Position found = null;\n      return found;\n   \}\n\n   synchronized public void walkToRoom (Position destination) \{\n   \}\n\n   synchronized public void walkToRoom (String destinationString) \{\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0; i < rooms.size(); i++)\{\n         if (((Room) rooms.elementAt(i)).getID().equals(destinationString))\{\n            destination = ((Room) rooms.elementAt(i));\n         \}\n\n      \}\n\n            outputMessage(\"I'll try going to \" + destination.getID() + \".  Gotta find the shortest path!\");\n      long start = (new java.util.Date()).getTime();\n      Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n      long stop = (new java.util.Date()).getTime();\n      if(v.size()-1 == -1) \{\n         destination = null;\n         Vector rooms1 = gameController.getBoard().map.getNodes(\"rooms\");\n         for(int i = 0; i < rooms1.size(); i++) \{\n            v = gameController.getBoard().map.routeTo(me.getPosition(), (Position) rooms1.elementAt(i));\n            if(v.size()-1 == -1) \{\n               continue;\n            \}\n\n            else \{\n               destination = (Position) rooms1.elementAt(i);\n               break;\n            \}\n\n         \}\n\n         if(destination == null)\{\n            return;\n         \}\n\n      \}\n\n      outputMessage(\"I'll need \" + (v.size()-1) + \" moves to get there.\");\n      outputMessage(\"Well, I'm allowed to make \" + allowedMoves + \".  That means...\");\n      if (v.size() > allowedMoves+1 ) \{\n         outputMessage(\"I can't get there, but I'll try to get close.\");\n         Room stopOver = null;\n         int i = 0;\n         for(i = 1; i < allowedMoves+1; i++)\{\n            if( v.elementAt(i) instanceof Room) \{\n               stopOver = ((Room)v.elementAt(i));\n               break;\n            \}\n\n         \}\n\n         if(stopOver == null) \{\n            movePlayer(((Position)v.elementAt(allowedMoves)), v, v.size());\n         \}\n\n         else \{\n            outputMessage(\"Room in my path, must stop at \" + stopOver.getID());\n            movePlayer(stopOver, v, i+1);\n         \}\n\n      \}\n\n      else \{\n         outputMessage(\"I can get there!  Time to start walking...\");\n         Room stopOver = null;\n         int i = 0;\n         for(i = 1; i < v.size(); i++)            if( v.elementAt(i) instanceof Room) \{\n               stopOver = ((Room)v.elementAt(i));\n               break;\n            \}\n\n         if(stopOver == null) \{\n            movePlayer(destination, v, v.size());\n         \}\n\n         else \{\n            outputMessage(\"Room in my path, must stop at \" + stopOver.getID());\n            movePlayer(stopOver, v, i+1);\n         \}\n\n         motive = \"findRoom\";\n      \}\n\n      if(me.getPosition() == destination ) \{\n         motive = \"findRoom\";\n         outputMessage(\"Just got to my destination!\");\n      \}\n\n      sleepFor(sleepPeriod);\n      if(me.getPosition() instanceof Room) \{\n           outputMessage(\"...which is the room I wanted to go to, YAY!\");\n      \}\n\n   \}\n\n   synchronized public Position findRoom() \{\n      return findRoom(false);\n   \}\n\n   synchronized public Position findRoom(boolean randomFirst) \{\n      Position destination = null;\n      return destination;\n    \}\n\n";
    var code5:String = "   synchronized public boolean shouldAccuse() \{\n      return false;\n   \}\n\n";
    var code6:String = "   synchronized public boolean accuse(String suspect, String weapon, String room) \{\n      Card weapon_kuno = new Card(weapon, \"Weapon\");\n      Card suspect_kuno = new Card(suspect, \"Suspect\");\n      Card room_kuno = new Card(room, \"Room\");\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getCards();\n      CardCollection myDCards = me.getDetectivePad().getCardList();\n      outputMessage(\"I accuse \" + suspect + \" using \" + weapon + \" at the \" + room);\n      return accuseCorrect(suspect_kuno, weapon_kuno, room_kuno);\n   \}\n\n      synchronized public boolean accuseCorrect(Card suspectCard, Card weaponCard, Card roomCard) \{\n         boolean result = false;\n         if(gameController.getBoard().getEnvelope().containsCard(weaponCard)  &&               gameController.getBoard().getEnvelope().containsCard(roomCard) &&               gameController.getBoard().getEnvelope().containsCard(suspectCard)               )         \{\n            result = true;\n         \}\n\n         else \{\n            result = false;\n         \}\n\n         return result;\n   \}\n\n   public String suggest() \{\n      return \"\";   \}\n\n      public String suggest(String weapon, String suspect) \{\n      Card suspectCard = new Card(weapon, \"Weapon\");\n;\n      Card weaponCard = new Card(suspect, \"Suspect\");\n;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myDCards = me.getDetectivePad().getCardList();\n      Card roomCard = gameController.getBoard().getCardPack().cardByName(me.getPosition().getID());\n      Vector disproofInfo = findDisproveCandidate(suspectCard, weaponCard, roomCard);\n      Player playerCandidate = (Player)disproofInfo.firstElement();\n      outputMessage(\"- I suspect \" + suspectCard.getName() + \" of using the \" + weaponCard.getName() + \" in the \" + me.getPosition().getID()+\".\\n\");\n      moveDefendant(suspectCard);\n      if(playerCandidate != null) \{\n         disproofReceived = false;\n         Message suggestionAlertMessage = new Message();\n         Vector params = new Vector();\n         params.add(new SuggestionAlert(suspectCard, weaponCard, roomCard, me.getRealName()) );\n         suggestionAlertMessage.parameters = params;\n         suggestionAlertMessage.type = \"suggestionAlert\";\n         suggestionAlertMessage.data = playerCandidate.getRealName();\n         gameController.relayMessage(suggestionAlertMessage);\n      \}\n\n      else \{\n         outputMessage(\"Apparently, I shouldn't suspect anyone to disprove it.\");\n      \}\n\n      while ( disproofReceived == false ) \{\n         try \{\n            Thread.sleep(100);\n         \}\n\n         catch(Exception e) \{\n         \}\n\n      \}\n\n            DisproofAlert disproofAlert = (DisproofAlert)incomingDisproof.parameters.firstElement();\n      SuggestionAlert originalSuggestionAlert = disproofAlert.getOriginalSuggestion();\n      disproofCard = disproofAlert.getCardShown();\n      disproofPerson = disproofAlert.getDisprovedBy();\n      if (!disproofPerson.equals(\"\"))\{\n         outputMessage(disproofPerson + \" disproved my suggestion using \" + disproofCard);\n      \}\n\n      else\{\n         outputMessage(\"Yup, nobody could really disprove.\");\n      \}\n\n      updateSuggestStatus();\n      disproofReceived = false;\n      return \"\";\n   \}\n\n   public void updateSuggestStatus() \{\n      Vector param = new Vector();\n      param = new Vector();\n      param.add(gameController.getBoard().getPlayer(myName));\n      gameController.directCommand(\"markSuggestMade\", param);\n   \}\n\n   public void registerSuggestion(String shown) \{\n      Vector param = new Vector();\n      param.add(shown);\n      gameController.directCommand(\"eliminateCard\", param);\n   \}\n\n   private void registerSuggestion(Card shown) \{\n      registerSuggestion(shown.getName());\n   \}\n\n   synchronized public void movePlayer(Position target, Vector path, int amount) \{\n      String output = \"\";\n      Vector pathTaken = applyConstraint(target, path);\n      Player me = gameController.getBoard().getPlayer(myName);\n      outputMessage(\"Moving the player \" + target.getID());\n      me.setMovesRemaining(0);\n      Vector param = new Vector();\n      param.add(target);\n      param.add(me);\n      param.add(pathTaken);\n      gameController.directCommand(\"movePlayer\", param);\n   \}\n\n      private Vector applyConstraint(Position target, Vector path) \{\n      Vector altPath = new Vector();\n      for(int i=0;i<path.size();i++) \{\n         if(path.elementAt(i) == target) \{\n            altPath.add(path.elementAt(i));\n            break;\n         \}\n\n         else\{\n            altPath.add(path.elementAt(i));\n         \}\n\n      \}\n\n      return altPath;\n   \}\n\n   public int rollDice() \{\n      Player me = gameController.getBoard().getPlayer(myName);\n      gameController.directCommand(\"roll\", new Vector());\n      hasRolledDice = true;\n      outputMessage(\"I rolled the dice to get: \" + me.getMovesRemaining());\n      return me.getMovesRemaining();\n   \}\n\n   public Vector findDisproveCandidate( Card who, Card what, Card where ) \{\n      Vector results = new Vector();\n      String output = \"\";\n      Player playerWithCard = null;\n      Vector cardsFound = new Vector();\n      Player currentPlayer = gameController.getBoard().getCurrentPlayer();\n      Player defendant = gameController.getBoard().getCharacter(who.getName());\n      if(!currentPlayer.getCharacter().equals(who.getName())) \{\n         if(defendant != null) \{\n            Position oldRoom = defendant.getPosition();\n            Position destination = currentPlayer.getPosition();\n            Vector parameters = new Vector();\n            parameters.add(destination);\n            parameters.add(defendant);\n            gameController.directCommand( \"movePlayer\", parameters );\n         \}\n\n      \}\n\n      playerWithCard = null;\n      cardsFound = new Vector();\n      Vector playersToParse = localArrangePlayersBy(currentPlayer);\n      for(int i = 0; i < playersToParse.size(); i++) \{\n         playerWithCard = (Player)playersToParse.elementAt(i);\n         if(playerWithCard != currentPlayer) \{\n            if(playerWithCard.hasCard(who))               cardsFound.add(who);\n            if(playerWithCard.hasCard(what))               cardsFound.add(what);\n            if(playerWithCard.hasCard(where))               cardsFound.add(where);\n            if(cardsFound.size() > 0)               break;\n         \}\n\n      \}\n\n      if(cardsFound.size() > 0) \{\n         output += playerWithCard.getRealName() + \", you'll have to disprove my suggestion. :-\\n \";\n         outputMessage(\"(findCandidatePlayer) \" + playerWithCard.getRealName() + \", you'll have to disprove my suggestion. :-\\n \");\n         for(int i = 0; i < cardsFound.size(); i++) \{\n            output += ((Card)cardsFound.elementAt(i)).getName() + \" \";\n         \}\n\n      \}\n\n      else \{\n         outputMessage(\"(findCandidatePlayer) No one shall be able to disprove the suggestion.\");\n         output += \"Unable to disprove the suggestion.\";\n      \}\n\n               results.add(playerWithCard);\n      results.add(cardsFound);\n      return results;\n   \}\n\n   private Vector localArrangePlayersBy(Player currentPlayer) \{\n      Vector players = new Vector();\n      int playerPosition = gameController.getBoard().getPlayerIndex(currentPlayer);\n      Vector livePlayers = gameController.getBoard().getPlayers();\n      for(int i = playerPosition + 1; i < livePlayers.size(); i++)\{\n         players.add(livePlayers.elementAt(i));\n      \}\n\n      if(!( playerPosition == 0)) \{\n         for(int i = 0; i < playerPosition; i++)\{\n            players.add(livePlayers.elementAt(i));\n         \}\n\n      \}\n\n      return players;\n   \}\n\n     public void moveDefendant(Card suspect) \{\n      Player defendant = gameController.getBoard().getCharacter(suspect.getName());\n      Player me = gameController.getBoard().getPlayer(myName);\n      Card testCard = null;\n      Card room = gameController.getBoard().getCardPack().cardByName(me.getPosition().getID());\n      if(defendant != null) \{\n         String output = \"\";\n         if(defendant != null) \{\n            Position oldRoom = defendant.getPosition();\n            Position destination = me.getPosition();\n            Vector parameters = new Vector();\n            parameters.add(destination);\n            parameters.add(defendant);\n            gameController.directCommand( \"movePlayer\", parameters );\n         \}\n\n         outputMessage(\"Called defendant\" + defendant.getRealName() + \" into the \" + room.getName());\n      \}\n\n   \}\n\n";
    var code7:String = "   @Override\n   public boolean makeAccusation() \{\n      // TODO Auto-generated method stub\n      return false;\n   \}\n\n";
    var codeCanReach:String = "   private boolean canReachHall()\{\n      String walkInfo = \"\";\n      String output = \"\";\n      String roomName = \"Hall\";\n      Position destination = null;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0; i < rooms.size(); i++)\{\n         if (((Room) rooms.elementAt(i)).getID().equals(roomName))\{\n            destination = ((Room) rooms.elementAt(i));\n         \}\n\n      \}\n\n      if(gameController.getBoard().getPlayer(myName) != gameController.getBoard().getCurrentPlayer())\{\n         System.out.println(\"+ I'm not feeling myself!! \");\n         System.out.println(\"+ getCurrentPlayer() \" + gameController.getBoard().getCurrentPlayer() + \" \"  + gameController.getBoard().getCurrentPlayer().getRealName());\n         System.out.println(\"+ getPlayer(\"+myName+\") \" + gameController.getBoard().getPlayer(myName) + \" \"  + gameController.getBoard().getPlayer(myName).getRealName());\n      \}\n\n      System.out.println(\"+ Dice: \" + allowedMoves);\n      walkInfo += \"Let's see, what the best path to the \"+destination.getID()+\" is..\\n\";\n      long start = (new java.util.Date()).getTime();\n            Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n      long stop = (new java.util.Date()).getTime();\n      if(v.size()-1 == -1) \{\n         destination = null;\n         Vector rooms1 = gameController.getBoard().map.getNodes(\"rooms\");\n         for(int i = 0; i < rooms1.size(); i++)\{\n            v = gameController.getBoard().map.routeTo(me.getPosition(), (Position) rooms1.elementAt(i));\n            System.out.println(\"Trying to get another room..\");\n            if(v.size()-1 == -1) \{\n               continue;\n            \}\n\n            else \{\n               destination = (Position) rooms1.elementAt(i);\n               break;\n            \}\n\n         \}\n\n         if(destination == null)\{\n            return false;\n         \}\n\n      \}\n\n      walkInfo += \"Hmm.. about \"+(v.size()-1)+\" moves, i'd say..\\n\";\n      walkInfo += \"Starting at: \";\n      for(int i = 0; i < v.size(); i++)\{\n         walkInfo += \" -> \" + ((Position)v.elementAt(i)).getID();\n      \}\n\n      walkInfo += \"\\nWell, I'm allowed to make \" + allowedMoves+\" moves, let's see about that\\n\";\n      if (allowedMoves >= (v.size()-1))\{\n         return true;\n      \}\n\n      else\{\n         return false;\n      \}\n\n   \}\n\n   private boolean canReachConservatory()\{\n      String walkInfo = \"\";\n      String output = \"\";\n      String roomName = \"Conservatory\";\n      Position destination = null;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0; i < rooms.size(); i++)\{\n         if (((Room) rooms.elementAt(i)).getID().equals(roomName))\{\n            destination = ((Room) rooms.elementAt(i));\n         \}\n\n      \}\n\n      if(gameController.getBoard().getPlayer(myName) != gameController.getBoard().getCurrentPlayer()) \{\n         System.out.println(\"+ I'm not feeling myself!! \");\n         System.out.println(\"+ getCurrentPlayer() \" + gameController.getBoard().getCurrentPlayer() + \" \"  + gameController.getBoard().getCurrentPlayer().getRealName());\n         System.out.println(\"+ getPlayer(\"+myName+\") \" + gameController.getBoard().getPlayer(myName) + \" \"  + gameController.getBoard().getPlayer(myName).getRealName());\n      \}\n\n      System.out.println(\"+ Dice: \" + allowedMoves);\n      walkInfo += \"Let's see, what the best path to the \"+destination.getID()+\" is..\\n\";\n      long start = (new java.util.Date()).getTime();\n            Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n      long stop = (new java.util.Date()).getTime();\n      if(v.size()-1 == -1) \{\n         destination = null;\n         Vector rooms1 = gameController.getBoard().map.getNodes(\"rooms\");\n         for(int i = 0; i < rooms1.size(); i++) \{\n            v = gameController.getBoard().map.routeTo(me.getPosition(), (Position) rooms1.elementAt(i));\n            System.out.println(\"Trying to get another room..\");\n            if(v.size()-1 == -1) \{\n               continue;\n            \}\n\n            else \{\n               destination = (Position) rooms1.elementAt(i);\n               break;\n            \}\n\n         \}\n\n         if(destination == null)            return false;\n      \}\n\n      walkInfo += \"Hmm.. about \"+(v.size()-1)+\" moves, i'd say..\\n\";\n      walkInfo += \"Starting at: \";\n      for(int i = 0; i < v.size(); i++)\{\n         walkInfo += \" -> \" + ((Position)v.elementAt(i)).getID();\n      \}\n\n      walkInfo += \"\\nWell, I'm allowed to make \" + allowedMoves+\" moves, let's see about that\\n\";\n      if (allowedMoves >= (v.size()-1))\{\n                  return true;\n      \}\n\n      else\{\n         return false;\n      \}\n\n   \}\n\n   private boolean canReachStudy()\{\n      String walkInfo = \"\";\n      String output = \"\";\n      String roomName = \"Study\";\n      Position destination = null;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0; i < rooms.size(); i++)\{\n         if (((Room) rooms.elementAt(i)).getID().equals(roomName))\{\n            destination = ((Room) rooms.elementAt(i));\n         \}\n\n      \}\n\n      if(gameController.getBoard().getPlayer(myName) != gameController.getBoard().getCurrentPlayer()) \{\n         System.out.println(\"+ I'm not feeling myself!! \");\n         System.out.println(\"+ getCurrentPlayer() \" + gameController.getBoard().getCurrentPlayer() + \" \"  + gameController.getBoard().getCurrentPlayer().getRealName());\n         System.out.println(\"+ getPlayer(\"+myName+\") \" + gameController.getBoard().getPlayer(myName) + \" \"  + gameController.getBoard().getPlayer(myName).getRealName());\n      \}\n\n      System.out.println(\"+ Dice: \" + allowedMoves);\n      walkInfo += \"Let's see, what the best path to the \"+destination.getID()+\" is..\\n\";\n      long start = (new java.util.Date()).getTime();\n            Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n      long stop = (new java.util.Date()).getTime();\n      if(v.size()-1 == -1) \{\n         destination = null;\n         Vector rooms1 = gameController.getBoard().map.getNodes(\"rooms\");\n         for(int i = 0; i < rooms1.size(); i++) \{\n            v = gameController.getBoard().map.routeTo(me.getPosition(), (Position) rooms1.elementAt(i));\n            System.out.println(\"Trying to get another room..\");\n            if(v.size()-1 == -1) \{\n               continue;\n            \}\n\n            else \{\n               destination = (Position) rooms1.elementAt(i);\n               break;\n            \}\n\n         \}\n\n         if(destination == null)\{\n            return false;\n         \}\n\n      \}\n\n      walkInfo += \"Hmm.. about \"+(v.size()-1)+\" moves, i'd say..\\n\";\n      walkInfo += \"Starting at: \";\n      for(int i = 0; i < v.size(); i++)\{\n         walkInfo += \" -> \" + ((Position)v.elementAt(i)).getID();\n      \}\n\n      walkInfo += \"\\nWell, I'm allowed to make \" + allowedMoves+\" moves, let's see about that\\n\";\n      if (allowedMoves >= (v.size()-1))\{\n         return true;\n      \}\n\n      else\{\n         return false;\n      \}\n\n   \}\n\n   private boolean canReachBilliardRoom()\{\n      String walkInfo = \"\";\n      String output = \"\";\n      String roomName = \"BilliardRoom\";\n      Position destination = null;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0; i < rooms.size(); i++)\{\n         if (((Room) rooms.elementAt(i)).getID().equals(roomName))\{\n            destination = ((Room) rooms.elementAt(i));\n         \}\n\n      \}\n\n      if(gameController.getBoard().getPlayer(myName) != gameController.getBoard().getCurrentPlayer()) \{\n         System.out.println(\"+ I'm not feeling myself!! \");\n         System.out.println(\"+ getCurrentPlayer() \" + gameController.getBoard().getCurrentPlayer() + \" \"  + gameController.getBoard().getCurrentPlayer().getRealName());\n         System.out.println(\"+ getPlayer(\"+myName+\") \" + gameController.getBoard().getPlayer(myName) + \" \"  + gameController.getBoard().getPlayer(myName).getRealName());\n      \}\n\n      System.out.println(\"+ Dice: \" + allowedMoves);\n      walkInfo += \"Let's see, what the best path to the \"+destination.getID()+\" is..\\n\";\n      long start = (new java.util.Date()).getTime();\n            Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n      long stop = (new java.util.Date()).getTime();\n      if(v.size()-1 == -1) \{\n         destination = null;\n         Vector rooms1 = gameController.getBoard().map.getNodes(\"rooms\");\n         for(int i = 0; i < rooms1.size(); i++) \{\n            v = gameController.getBoard().map.routeTo(me.getPosition(), (Position) rooms1.elementAt(i));\n            System.out.println(\"Trying to get another room..\");\n                        if(v.size()-1 == -1) \{\n               continue;\n            \}\n\n            else \{\n               destination = (Position) rooms1.elementAt(i);\n               break;\n            \}\n\n         \}\n\n         if(destination == null)            return false;\n      \}\n\n      walkInfo += \"Hmm.. about \"+(v.size()-1)+\" moves, i'd say..\\n\";\n      walkInfo += \"Starting at: \";\n      for(int i = 0; i < v.size(); i++)\{\n         walkInfo += \" -> \" + ((Position)v.elementAt(i)).getID();\n      \}\n\n      walkInfo += \"\\nWell, I'm allowed to make \" + allowedMoves+\" moves, let's see about that\\n\";\n      if (allowedMoves >= (v.size()-1))\{\n         return true;\n      \}\n\n      else\{\n         return false;\n      \}\n\n   \}\n\n   private boolean canReachLibrary()\{\n      String walkInfo = \"\";\n      String output = \"\";\n      String roomName = \"Library\";\n      Position destination = null;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0; i < rooms.size(); i++)\{\n         if (((Room) rooms.elementAt(i)).getID().equals(roomName))            destination = ((Room) rooms.elementAt(i));\n      \}\n\n      if(gameController.getBoard().getPlayer(myName) != gameController.getBoard().getCurrentPlayer()) \{\n         System.out.println(\"+ I'm not feeling myself!! \");\n                  System.out.println(\"+ getCurrentPlayer() \" + gameController.getBoard().getCurrentPlayer() + \" \"  + gameController.getBoard().getCurrentPlayer().getRealName());\n         System.out.println(\"+ getPlayer(\"+myName+\") \" + gameController.getBoard().getPlayer(myName) + \" \"  + gameController.getBoard().getPlayer(myName).getRealName());\n      \}\n\n      System.out.println(\"+ Dice: \" + allowedMoves);\n      walkInfo += \"Let's see, what the best path to the \"+destination.getID()+\" is..\\n\";\n      long start = (new java.util.Date()).getTime();\n            Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n      long stop = (new java.util.Date()).getTime();\n      if(v.size()-1 == -1) \{\n         destination = null;\n         Vector rooms1 = gameController.getBoard().map.getNodes(\"rooms\");\n         for(int i = 0; i < rooms1.size(); i++) \{\n            v = gameController.getBoard().map.routeTo(me.getPosition(), (Position) rooms1.elementAt(i));\n            System.out.println(\"Trying to get another room..\");\n            if(v.size()-1 == -1) \{\n               continue;\n            \}\n\n            else \{\n               destination = (Position) rooms1.elementAt(i);\n               break;\n            \}\n\n         \}\n\n         if(destination == null)            return false;\n      \}\n\n      walkInfo += \"Hmm.. about \"+(v.size()-1)+\" moves, i'd say..\\n\";\n      walkInfo += \"Starting at: \";\n      for(int i = 0;\n i < v.size();\n i++)         walkInfo += \" -> \" + ((Position)v.elementAt(i)).getID();\n      walkInfo += \"\\nWell, I'm allowed to make \" + allowedMoves+\" moves, let's see about that\\n\";\n      if (allowedMoves >= (v.size()-1))\{\n         return true;\n      \}\n\n      else\{\n         return false;\n      \}\n\n   \}\n\n   private boolean canReachBallroom()\{\n      String walkInfo = \"\";\n      String output = \"\";\n      String roomName = \"Ballroom\";\n      Position destination = null;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0; i < rooms.size(); i++)\{\n         if (((Room) rooms.elementAt(i)).getID().equals(roomName))\{\n            destination = ((Room) rooms.elementAt(i));\n         \}\n\n      \}\n\n      if(gameController.getBoard().getPlayer(myName) != gameController.getBoard().getCurrentPlayer()) \{\n         System.out.println(\"+ I'm not feeling myself!! \");\n         System.out.println(\"+ getCurrentPlayer() \" + gameController.getBoard().getCurrentPlayer() + \" \"  + gameController.getBoard().getCurrentPlayer().getRealName());\n         System.out.println(\"+ getPlayer(\"+myName+\") \" + gameController.getBoard().getPlayer(myName) + \" \"  + gameController.getBoard().getPlayer(myName).getRealName());\n      \}\n\n      System.out.println(\"+ Dice: \" + allowedMoves);\n      walkInfo += \"Let's see, what the best path to the \"+destination.getID()+\" is..\\n\";\n      long start = (new java.util.Date()).getTime();\n            Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n      long stop = (new java.util.Date()).getTime();\n      if(v.size()-1 == -1) \{\n         destination = null;\n         Vector rooms1 = gameController.getBoard().map.getNodes(\"rooms\");\n         for(int i = 0; i < rooms1.size(); i++) \{\n            v = gameController.getBoard().map.routeTo(me.getPosition(), (Position) rooms1.elementAt(i));\n            System.out.println(\"Trying to get another room..\");\n            if(v.size()-1 == -1) \{\n               continue;\n            \}\n\n            else \{\n               destination = (Position) rooms1.elementAt(i);\n               break;\n            \}\n\n         \}\n\n         if(destination == null)\{\n            return false;\n         \}\n\n      \}\n\n      walkInfo += \"Hmm.. about \"+(v.size()-1)+\" moves, i'd say..\\n\";\n      walkInfo += \"Starting at: \";\n      for(int i = 0; i < v.size(); i++)\{\n         walkInfo += \" -> \" + ((Position)v.elementAt(i)).getID();\n      \}\n\n      walkInfo += \"\\nWell, I'm allowed to make \" + allowedMoves+\" moves, let's see about that\\n\";\n      if (allowedMoves >= (v.size()-1))\{\n         return true;\n      \}\n\n      else\{\n         return false;\n      \}\n\n   \}\n\n   private boolean canReachLounge()\{\n      String walkInfo = \"\";\n      String output = \"\";\n      String roomName = \"Lounge\";\n      Position destination = null;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0; i < rooms.size(); i++)\{\n         if (((Room) rooms.elementAt(i)).getID().equals(roomName))\{\n            destination = ((Room) rooms.elementAt(i));\n         \}\n\n      \}\n\n      if(gameController.getBoard().getPlayer(myName) != gameController.getBoard().getCurrentPlayer()) \{\n         System.out.println(\"+ I'm not feeling myself!! \");\n         System.out.println(\"+ getCurrentPlayer() \" + gameController.getBoard().getCurrentPlayer() + \" \"  + gameController.getBoard().getCurrentPlayer().getRealName());\n         System.out.println(\"+ getPlayer(\"+myName+\") \" + gameController.getBoard().getPlayer(myName) + \" \"  + gameController.getBoard().getPlayer(myName).getRealName());\n      \}\n\n      System.out.println(\"+ Dice: \" + allowedMoves);\n      walkInfo += \"Let's see, what the best path to the \"+destination.getID()+\" is..\\n\";\n      long start = (new java.util.Date()).getTime();\n            Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n      long stop = (new java.util.Date()).getTime();\n      if(v.size()-1 == -1) \{\n         destination = null;\n         Vector rooms1 = gameController.getBoard().map.getNodes(\"rooms\");\n         for(int i = 0; i < rooms1.size(); i++) \{\n            v = gameController.getBoard().map.routeTo(me.getPosition(), (Position) rooms1.elementAt(i));\n            System.out.println(\"Trying to get another room..\");\n            if(v.size()-1 == -1) \{\n               continue;\n            \}\n\n            else \{\n               destination = (Position) rooms1.elementAt(i);\n               break;\n            \}\n\n         \}\n\n         if(destination == null)\{\n            return false;\n         \}\n\n      \}\n\n      walkInfo += \"Hmm.. about \"+(v.size()-1)+\" moves, i'd say..\\n\";\n      walkInfo += \"Starting at: \";\n      for(int i = 0; i < v.size(); i++)\{\n         walkInfo += \" -> \" + ((Position)v.elementAt(i)).getID();\n      \}\n\n      walkInfo += \"\\nWell, I'm allowed to make \" + allowedMoves+\" moves, let's see about that\\n\";\n      if (allowedMoves >= (v.size()-1))\{\n                  return true;\n      \}\n\n      else\{\n         return false;\n      \}\n\n   \}\n\n   private boolean canReachKitchen()\{\n      String walkInfo = \"\";\n      String output = \"\";\n      String roomName = \"Kitchen\";\n      Position destination = null;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0; i < rooms.size(); i++)\{\n         if (((Room) rooms.elementAt(i)).getID().equals(roomName))\{\n            destination = ((Room) rooms.elementAt(i));\n         \}\n\n      \}\n\n      if(gameController.getBoard().getPlayer(myName) != gameController.getBoard().getCurrentPlayer()) \{\n         System.out.println(\"+ I'm not feeling myself!! \");\n         System.out.println(\"+ getCurrentPlayer() \" + gameController.getBoard().getCurrentPlayer() + \" \"  + gameController.getBoard().getCurrentPlayer().getRealName());\n         System.out.println(\"+ getPlayer(\"+myName+\") \" + gameController.getBoard().getPlayer(myName) + \" \"  + gameController.getBoard().getPlayer(myName).getRealName());\n      \}\n\n      System.out.println(\"+ Dice: \" + allowedMoves);\n      walkInfo += \"Let's see, what the best path to the \"+destination.getID()+\" is..\\n\";\n      long start = (new java.util.Date()).getTime();\n            Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n      long stop = (new java.util.Date()).getTime();\n      if(v.size()-1 == -1) \{\n         destination = null;\n         Vector rooms1 = gameController.getBoard().map.getNodes(\"rooms\");\n         for(int i = 0; i < rooms1.size(); i++) \{\n            v = gameController.getBoard().map.routeTo(me.getPosition(), (Position) rooms1.elementAt(i));\n            System.out.println(\"Trying to get another room..\");\n            if(v.size()-1 == -1) \{\n               continue;\n            \}\n\n            else \{\n               destination = (Position) rooms1.elementAt(i);\n               break;\n            \}\n\n         \}\n\n         if(destination == null)\{\n            return false;\n         \}\n\n      \}\n\n      walkInfo += \"Hmm.. about \"+(v.size()-1)+\" moves, i'd say..\\n\";\n      walkInfo += \"Starting at: \";\n      for(int i = 0; i < v.size(); i++)\{\n         walkInfo += \" -> \" + ((Position)v.elementAt(i)).getID();\n      \}\n\n      walkInfo += \"\\nWell, I'm allowed to make \" + allowedMoves+\" moves, let's see about that\\n\";\n      if (allowedMoves >= (v.size()-1))\{\n         return true;\n      \}\n\n      else\{\n         return false;\n      \}\n\n   \}\n\n   private boolean canReachDiningRoom()\{\n      String walkInfo = \"\";\n      String output = \"\";\n      String roomName = \"DiningRoom\";\n      Position destination = null;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0; i < rooms.size(); i++)\{\n         if (((Room) rooms.elementAt(i)).getID().equals(roomName))\{\n            destination = ((Room) rooms.elementAt(i));\n         \}\n\n      \}\n\n      if(gameController.getBoard().getPlayer(myName) != gameController.getBoard().getCurrentPlayer()) \{\n         System.out.println(\"+ I'm not feeling myself!! \");\n         System.out.println(\"+ getCurrentPlayer() \" + gameController.getBoard().getCurrentPlayer() + \" \"  + gameController.getBoard().getCurrentPlayer().getRealName());\n         System.out.println(\"+ getPlayer(\"+myName+\") \" + gameController.getBoard().getPlayer(myName) + \" \"  + gameController.getBoard().getPlayer(myName).getRealName());\n      \}\n\n      System.out.println(\"+ Dice: \" + allowedMoves);\n      walkInfo += \"Let's see, what the best path to the \"+destination.getID()+\" is..\\n\";\n      long start = (new java.util.Date()).getTime();\n            Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n      long stop = (new java.util.Date()).getTime();\n      if(v.size()-1 == -1) \{\n         destination = null;\n         Vector rooms1 = gameController.getBoard().map.getNodes(\"rooms\");\n         for(int i = 0; i < rooms1.size(); i++) \{\n            v = gameController.getBoard().map.routeTo(me.getPosition(), (Position) rooms1.elementAt(i));\n            System.out.println(\"Trying to get another room..\");\n            if(v.size()-1 == -1) \{\n               continue;\n            \}\n\n            else \{\n               destination = (Position) rooms1.elementAt(i);\n               break;\n            \}\n\n         \}\n\n         if(destination == null)\{\n            return false;\n         \}\n\n      \}\n\n      walkInfo += \"Hmm.. about \"+(v.size()-1)+\" moves, i'd say..\\n\";\n      walkInfo += \"Starting at: \";\n      for(int i = 0; i < v.size(); i++)\{\n         walkInfo += \" -> \" + ((Position)v.elementAt(i)).getID();\n      \}\n\n      walkInfo += \"\\nWell, I'm allowed to make \" + allowedMoves+\" moves, let's see about that\\n\";\n      if (allowedMoves >= (v.size()-1))\{\n         return true;\n      \}\n\n      else\{\n         return false;\n      \}\n\n   \}\n";
    var codeHaveSug:String  = "   private boolean iHaveSugWeap()   \{\n      boolean have = false;\n      if (card1.contentEquals(suggestedWeapon))\{\n         have = true;\n      \}\n\n      if (card2.contentEquals(suggestedWeapon))\{\n         have = true;\n      \}\n\n      if (card3.contentEquals(suggestedWeapon))\{\n         have = true;\n      \}\n\n      if (card4.contentEquals(suggestedWeapon))\{\n         have = true;\n      \}\n\n      if (card5.contentEquals(suggestedWeapon))\{\n         have = true;\n      \}\n\n      if (card6.contentEquals(suggestedWeapon))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have the suggested weapon.\");\n      \}\n\n      return have;\n   \}\n\n   private boolean iHaveSugSusp()   \{\n      boolean have = false;\n      if (card1.contentEquals(suggestedSuspect))\{\n         have = true;\n      \}\n\n      if (card2.contentEquals(suggestedSuspect))\{\n         have = true;\n      \}\n\n      if (card3.contentEquals(suggestedSuspect))\{\n         have = true;\n      \}\n\n      if (card4.contentEquals(suggestedSuspect))\{\n         have = true;\n      \}\n\n      if (card5.contentEquals(suggestedSuspect))\{\n         have = true;\n      \}\n\n      if (card6.contentEquals(suggestedSuspect))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have the suggested suspect.\");\n      \}\n\n      return have;\n   \}\n\n   private boolean iHaveSugRoom()   \{\n      boolean have = false;\n      if (card1.contentEquals(suggestedRoom))\{\n         have = true;\n      \}\n\n      if (card2.contentEquals(suggestedRoom))\{\n         have = true;\n      \}\n\n      if (card3.contentEquals(suggestedRoom))\{\n         have = true;\n      \}\n\n      if (card4.contentEquals(suggestedRoom))\{\n         have = true;\n      \}\n\n      if (card5.contentEquals(suggestedRoom))\{\n         have = true;\n      \}\n\n      if (card6.contentEquals(suggestedRoom))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have the suggested room.\");\n      \}\n\n      return have;\n   \}\n\n";
    var codeHaveCard:String = "   private boolean iHaveHall()   \{\n      boolean have = false;\n      if (card1.equals(Hall))\{\n         have = true;\n      \}\n\n      if (card2.equals(Hall))\{\n         have = true;\n      \}\n\n      if (card3.equals(Hall))\{\n         have = true;\n      \}\n\n      if (card4.equals(Hall))\{\n         have = true;\n      \}\n\n      if (card5.equals(Hall))\{\n         have = true;\n      \}\n\n      if (card6.equals(Hall))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have Hall card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveConservatory()   \{\n      boolean have = false;\n      if (card1.equals(Conservatory))\{\n         have = true;\n      \}\n\n      if (card2.equals(Conservatory))\{\n         have = true;\n      \}\n\n      if (card3.equals(Conservatory))\{\n         have = true;\n      \}\n\n      if (card4.equals(Conservatory))\{\n         have = true;\n      \}\n\n      if (card5.equals(Conservatory))\{\n         have = true;\n      \}\n\n      if (card6.equals(Conservatory))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have Conservatory card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveStudy()   \{\n      boolean have = false;\n      if (card1.equals(Study))\{\n         have = true;\n      \}\n\n      if (card2.equals(Study))\{\n         have = true;\n      \}\n\n      if (card3.equals(Study))\{\n         have = true;\n      \}\n\n      if (card4.equals(Study))\{\n         have = true;\n      \}\n\n      if (card5.equals(Study))\{\n         have = true;\n      \}\n\n      if (card6.equals(Study))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have Study card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveBilliardRoom()   \{\n      boolean have = false;\n      if (card1.equals(BilliardRoom))\{\n         have = true;\n      \}\n\n      if (card2.equals(BilliardRoom))\{\n         have = true;\n      \}\n\n      if (card3.equals(BilliardRoom))\{\n         have = true;\n      \}\n\n      if (card4.equals(BilliardRoom))\{\n         have = true;\n      \}\n\n      if (card5.equals(BilliardRoom))\{\n         have = true;\n      \}\n\n      if (card6.equals(BilliardRoom))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have BilliardRoom card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveLibrary()   \{\n      boolean have = false;\n      if (card1.equals(Library))\{\n         have = true;\n      \}\n\n      if (card2.equals(Library))\{\n         have = true;\n      \}\n\n      if (card3.equals(Library))\{\n         have = true;\n      \}\n\n      if (card4.equals(Library))\{\n         have = true;\n      \}\n\n      if (card5.equals(Library))\{\n         have = true;\n      \}\n\n      if (card6.equals(Library))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have Library card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveBallroom()   \{\n      boolean have = false;\n      if (card1.equals(Ballroom))\{\n         have = true;\n      \}\n\n      if (card2.equals(Ballroom))\{\n         have = true;\n      \}\n\n      if (card3.equals(Ballroom))\{\n         have = true;\n      \}\n\n      if (card4.equals(Ballroom))\{\n         have = true;\n      \}\n\n      if (card5.equals(Ballroom))\{\n         have = true;\n      \}\n\n      if (card6.equals(Ballroom))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have Ballroom card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveLounge()   \{\n      boolean have = false;\n      if (card1.equals(Lounge))\{\n         have = true;\n      \}\n\n      if (card2.equals(Lounge))\{\n         have = true;\n      \}\n\n      if (card3.equals(Lounge))\{\n         have = true;\n      \}\n\n      if (card4.equals(Lounge))\{\n         have = true;\n      \}\n\n      if (card5.equals(Lounge))\{\n         have = true;\n      \}\n\n      if (card6.equals(Lounge))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have Lounge card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveKitchen()   \{\n      boolean have = false;\n      if (card1.equals(Kitchen))\{\n         have = true;\n      \}\n\n      if (card2.equals(Kitchen))\{\n         have = true;\n      \}\n\n      if (card3.equals(Kitchen))\{\n         have = true;\n      \}\n\n      if (card4.equals(Kitchen))\{\n         have = true;\n      \}\n\n      if (card5.equals(Kitchen))\{\n         have = true;\n      \}\n\n      if (card6.equals(Kitchen))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have Kitchen card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveDiningRoom()   \{\n      boolean have = false;\n      if (card1.equals(DiningRoom))\{\n         have = true;\n      \}\n\n      if (card2.equals(DiningRoom))\{\n         have = true;\n      \}\n\n      if (card3.equals(DiningRoom))\{\n         have = true;\n      \}\n\n      if (card4.equals(DiningRoom))\{\n         have = true;\n      \}\n\n      if (card5.equals(DiningRoom))\{\n         have = true;\n      \}\n\n      if (card6.equals(DiningRoom))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have DiningRoom card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveMrsWhite()   \{\n      boolean have = false;\n      if (card1.equals(MrsWhite))\{\n         have = true;\n      \}\n\n      if (card2.equals(MrsWhite))\{\n         have = true;\n      \}\n\n      if (card3.equals(MrsWhite))\{\n         have = true;\n      \}\n\n      if (card4.equals(MrsWhite))\{\n         have = true;\n      \}\n\n      if (card5.equals(MrsWhite))\{\n         have = true;\n      \}\n\n      if (card6.equals(MrsWhite))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have MrsWhite card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveMissScarlett()   \{\n      boolean have = false;\n      if (card1.equals(MissScarlett))\{\n         have = true;\n      \}\n\n      if (card2.equals(MissScarlett))\{\n         have = true;\n      \}\n\n      if (card3.equals(MissScarlett))\{\n         have = true;\n      \}\n\n      if (card4.equals(MissScarlett))\{\n         have = true;\n      \}\n\n      if (card5.equals(MissScarlett))\{\n         have = true;\n      \}\n\n      if (card6.equals(MissScarlett))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have MissScarlett card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveReverendGreen()   \{\n      boolean have = false;\n      if (card1.equals(ReverendGreen))\{\n         have = true;\n      \}\n\n      if (card2.equals(ReverendGreen))\{\n         have = true;\n      \}\n\n      if (card3.equals(ReverendGreen))\{\n         have = true;\n      \}\n\n      if (card4.equals(ReverendGreen))\{\n         have = true;\n      \}\n\n      if (card5.equals(ReverendGreen))\{\n         have = true;\n      \}\n\n      if (card6.equals(ReverendGreen))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have ReverendGreen card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveColonelMustard()   \{\n      boolean have = false;\n      if (card1.equals(ColonelMustard))\{\n         have = true;\n      \}\n\n      if (card2.equals(ColonelMustard))\{\n         have = true;\n      \}\n\n      if (card3.equals(ColonelMustard))\{\n         have = true;\n      \}\n\n      if (card4.equals(ColonelMustard))\{\n         have = true;\n      \}\n\n      if (card5.equals(ColonelMustard))\{\n         have = true;\n      \}\n\n      if (card6.equals(ColonelMustard))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have ColonelMustard card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveMrsPeacock()   \{\n      boolean have = false;\n      if (card1.equals(MrsPeacock))\{\n         have = true;\n      \}\n\n      if (card2.equals(MrsPeacock))\{\n         have = true;\n      \}\n\n      if (card3.equals(MrsPeacock))\{\n         have = true;\n      \}\n\n      if (card4.equals(MrsPeacock))\{\n         have = true;\n      \}\n\n      if (card5.equals(MrsPeacock))\{\n         have = true;\n      \}\n\n      if (card6.equals(MrsPeacock))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have MrsPeacock card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveProfessorPlum()   \{\n      boolean have = false;\n      if (card1.equals(ProfessorPlum))\{\n         have = true;\n      \}\n\n      if (card2.equals(ProfessorPlum))\{\n         have = true;\n      \}\n\n      if (card3.equals(ProfessorPlum))\{\n         have = true;\n      \}\n\n      if (card4.equals(ProfessorPlum))\{\n         have = true;\n      \}\n\n      if (card5.equals(ProfessorPlum))\{\n         have = true;\n      \}\n\n      if (card6.equals(ProfessorPlum))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have ProfessorPlum card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveRope()   \{\n      boolean have = false;\n      if (card1.equals(Rope))\{\n         have = true;\n      \}\n\n      if (card2.equals(Rope))\{\n         have = true;\n      \}\n\n      if (card3.equals(Rope))\{\n         have = true;\n      \}\n\n      if (card4.equals(Rope))\{\n         have = true;\n      \}\n\n      if (card5.equals(Rope))\{\n         have = true;\n      \}\n\n      if (card6.equals(Rope))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have Rope card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveDagger()   \{\n      boolean have = false;\n      if (card1.equals(Dagger))\{\n         have = true;\n      \}\n\n      if (card2.equals(Dagger))\{\n         have = true;\n      \}\n\n      if (card3.equals(Dagger))\{\n         have = true;\n      \}\n\n      if (card4.equals(Dagger))\{\n         have = true;\n      \}\n\n      if (card5.equals(Dagger))\{\n         have = true;\n      \}\n\n      if (card6.equals(Dagger))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have Dagger card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveSpanner()   \{\n      boolean have = false;\n      if (card1.equals(Spanner))\{\n         have = true;\n      \}\n\n      if (card2.equals(Spanner))\{\n         have = true;\n      \}\n\n      if (card3.equals(Spanner))\{\n         have = true;\n      \}\n\n      if (card4.equals(Spanner))\{\n         have = true;\n      \}\n\n      if (card5.equals(Spanner))\{\n         have = true;\n      \}\n\n      if (card6.equals(Spanner))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have Spanner card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveRevolver()   \{\n      boolean have = false;\n      if (card1.equals(Revolver))\{\n         have = true;\n      \}\n\n      if (card2.equals(Revolver))\{\n         have = true;\n      \}\n\n      if (card3.equals(Revolver))\{\n         have = true;\n      \}\n\n      if (card4.equals(Revolver))\{\n         have = true;\n      \}\n\n      if (card5.equals(Revolver))\{\n         have = true;\n      \}\n\n      if (card6.equals(Revolver))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have Revolver card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveLeadPipe()   \{\n      boolean have = false;\n      if (card1.equals(LeadPipe))\{\n         have = true;\n      \}\n\n      if (card2.equals(LeadPipe))\{\n         have = true;\n      \}\n\n      if (card3.equals(LeadPipe))\{\n         have = true;\n      \}\n\n      if (card4.equals(LeadPipe))\{\n         have = true;\n      \}\n\n      if (card5.equals(LeadPipe))\{\n         have = true;\n      \}\n\n      if (card6.equals(LeadPipe))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have LeadPipe card.\");\n      \}\n\n      return have;\n   \}\n\n      private boolean iHaveCandlestick()   \{\n      boolean have = false;\n      if (card1.equals(Candlestick))\{\n         have = true;\n      \}\n\n      if (card2.equals(Candlestick))\{\n         have = true;\n      \}\n\n      if (card3.equals(Candlestick))\{\n         have = true;\n      \}\n\n      if (card4.equals(Candlestick))\{\n         have = true;\n      \}\n\n      if (card5.equals(Candlestick))\{\n         have = true;\n      \}\n\n      if (card6.equals(Candlestick))\{\n         have = true;\n      \}\n\n      if (have == true)      \{\n         outputMessage(\"I just checked and yep, I have Candlestick card.\");\n      \}\n\n      return have;\n   \}\n\n";
    var codeRoomFuncs:String = "   private boolean isInsideRoom()\{\n      Player me = gameController.getBoard().getPlayer(myName);\n      return me.canSuggestHere();\n   \}\n\n       private String getRoomImInside()\{\n      Player me = gameController.getBoard().getPlayer(myName);\n      if (isInsideRoom())\{\n         return me.getPosition().getID();\n      \}\n\n      else\{\n         return \"\";\n      \}\n\n    \}\n\n      private String getNearestRoom()\{\n      int[] roomDistance = new int[9];\n      Position destination = null;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0;\n i < rooms.size();\n i++)\{\n         if (((Room)rooms.elementAt(i)).getID().equals(roomNameList[i]))\{\n            destination = ((Room) rooms.elementAt(i));\n            long start = (new java.util.Date()).getTime();\n            Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n            long stop = (new java.util.Date()).getTime();\n            outputMessage(\"Finding shortest path: \"+me.getPosition().getID()+\" to \"+destination.getID()+\" (\"+(stop-start)+\"ms)\");\n            roomDistance[i] = v.size() - 1;\n         \}\n\n      \}\n\n      int indexLowest = 0;\n      for (int i = 0;\n i < roomDistance.length;\n i++)\{\n         if (roomDistance[indexLowest] > roomDistance[i])         \{\n            indexLowest = i;\n         \}\n\n      \}\n\n      return roomNameList[indexLowest];\n   \}\n\n   private String getNearestInnoRoom()\{\n      int[] roomDistance = new int[9];\n      boolean[] dpRoom = new boolean[9];\n      dpRoom[0] = dpKitchen;\n      dpRoom[1] = dpDiningRoom;\n      dpRoom[2] = dpLounge;\n      dpRoom[3] = dpBallroom;\n      dpRoom[4] = dpHall;\n      dpRoom[5] = dpStudy;\n      dpRoom[6] = dpLibrary;\n      dpRoom[7] = dpBilliardRoom;\n      dpRoom[8] = dpConservatory;\n      Position destination = null;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0; i < rooms.size(); i++)\{\n         if (((Room)rooms.elementAt(i)).getID().equals(roomNameList[i]))\{\n            destination = ((Room) rooms.elementAt(i));\n            long start = (new java.util.Date()).getTime();\n            Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n            long stop = (new java.util.Date()).getTime();\n            outputMessage(\"Finding shortest path: \"+me.getPosition().getID()+\" to \"+destination.getID()+\" (\"+(stop-start)+\"ms)\");\n            roomDistance[i] = v.size() - 1;\n            \}\n\n      \}\n\n      int indexLowest = -1;\n      int currentDistance = Integer.MAX_VALUE;\n      for (int i = 0; i < roomDistance.length; i++)\{\n         if (dpRoom[i] == false)\{\n            if (currentDistance > roomDistance[i])\{\n               indexLowest = i;\n               currentDistance = roomDistance[i];\n            \}\n\n         \}\n\n      \}\n\n      if (indexLowest == -1)\{\n         return \"\";\n      \}\n\n      else      \{\n         return roomNameList[indexLowest];\n      \}\n\n    \}\n\n    private String getNearestForeignInnoRoom()\{\n      int[] roomDistance = new int[9];\n      boolean[] dpRoom = new boolean[9];\n      dpRoom[0] = dpKitchen;\n      dpRoom[1] = dpDiningRoom;\n      dpRoom[2] = dpLounge;\n      dpRoom[3] = dpBallroom;\n      dpRoom[4] = dpHall;\n      dpRoom[5] = dpStudy;\n      dpRoom[6] = dpLibrary;\n      dpRoom[7] = dpBilliardRoom;\n      dpRoom[8] = dpConservatory;\n      Position destination = null;\n      Player me = gameController.getBoard().getPlayer(myName);\n      CardCollection myCards = me.getDetectivePad().getCardList();\n      Vector rooms = gameController.getBoard().map.getNodes(\"rooms\");\n      for (int i = 0; i < rooms.size(); i++)\{\n         if (((Room)rooms.elementAt(i)).getID().equals(roomNameList[i]))\{\n            destination = ((Room) rooms.elementAt(i));\n            long start = (new java.util.Date()).getTime();\n            Vector v = gameController.getBoard().map.routeTo(me.getPosition(), destination);\n            long stop = (new java.util.Date()).getTime();\n            outputMessage(\"Finding shortest path: \"+me.getPosition().getID()+\" to \"+destination.getID()+\" (\"+(stop-start)+\"ms)\");\n            roomDistance[i] = v.size() - 1;\n         \}\n\n      \}\n\n      int indexLowest = -1;\n      int currentDistance = Integer.MAX_VALUE;\n      for (int i = 0; i < roomDistance.length; i++)\{\n         if (dpRoom[i] == false)\{\n            if (currentDistance > roomDistance[i] && !me.getPosition().getID().equals(roomNameList[i]))\{\n               indexLowest = i;\n               currentDistance = roomDistance[i];\n            \}\n\n         \}\n\n      \}\n\n      if (indexLowest == -1)\{\n         return \"\";\n      \}\n\n      else      \{\n         return roomNameList[indexLowest];\n      \}\n\n   \}\n\n";
    var codeIElim:String = "   private boolean iElimSugSusp()   \{\n      if (suggestedSuspect == \"MrsWhite\")      \{\n         return dpMrsWhite;\n      \}\n\n      else if (suggestedSuspect == \"MissScarlett\")      \{\n         return dpMissScarlett;\n      \}\n\n      else if (suggestedSuspect == \"ReverendGreen\")      \{\n         return dpReverendGreen;\n      \}\n\n      else if (suggestedSuspect == \"ColonelMustard\")      \{\n         return dpColonelMustard;\n      \}\n\n      else if (suggestedSuspect == \"MrsPeacock\")      \{\n         return dpMrsPeacock;\n      \}\n\n      else if (suggestedSuspect == \"ProfessorPlum\")      \{\n         return dpProfessorPlum;\n      \}\n\n      return false;\n   \}\n\n   private boolean iElimSugWeap()   \{\n      if (suggestedWeapon == \"Rope\")      \{\n         return dpRope;\n      \}\n\n      else if (suggestedWeapon == \"Dagger\")      \{\n         return dpDagger;\n      \}\n\n      else if (suggestedWeapon == \"Spanner\")      \{\n         return dpSpanner;\n      \}\n\n      else if (suggestedWeapon == \"Revolver\")      \{\n         return dpRevolver;\n      \}\n\n      else if (suggestedWeapon == \"LeadPipe\")      \{\n         return dpLeadPipe;\n      \}\n\n      else if (suggestedWeapon == \"Candlestick\")      \{\n         return dpCandlestick;\n      \}\n\n      return false;\n   \}\n\n   private boolean iElimSugRoom()   \{\n      if (suggestedRoom == \"Hall\")      \{\n         return dpHall;\n      \}\n\n      else if (suggestedRoom == \"Conservatory\")      \{\n         return dpConservatory;\n      \}\n\n      else if (suggestedRoom == \"Study\")      \{\n         return dpStudy;\n      \}\n\n      else if (suggestedRoom == \"BilliardRoom\")      \{\n         return dpBilliardRoom;\n      \}\n\n      else if (suggestedRoom == \"Library\")      \{\n         return dpLibrary;\n      \}\n\n      else if (suggestedRoom == \"Ballroom\")      \{\n         return dpBallroom;\n      \}\n\n      else if (suggestedRoom == \"Lounge\")      \{\n         return dpLounge;\n      \}\n\n      else if (suggestedRoom == \"Kitchen\")      \{\n         return dpKitchen;\n      \}\n\n      else if (suggestedRoom == \"DiningRoom\")      \{\n         return dpDiningRoom;\n      \}\n\n      return false;\n   \}\n\n";
    var codeGetARandInno:String = "   private String getARandInnoSusp()   \{\n      Vector possSusps = new Vector();\n      if (dpMrsWhite == false)      \{\n         possSusps.add(\"MrsWhite\");\n      \}\n\n      if (dpMissScarlett == false)      \{\n         possSusps.add(\"MissScarlett\");\n      \}\n\n      if (dpReverendGreen == false)      \{\n         possSusps.add(\"ReverendGreen\");\n      \}\n\n      if (dpColonelMustard == false)      \{\n         possSusps.add(\"ColonelMustard\");\n      \}\n\n      if (dpMrsPeacock == false)      \{\n         possSusps.add(\"MrsPeacock\");\n      \}\n\n      if (dpProfessorPlum == false)      \{\n         possSusps.add(\"ProfessorPlum\");\n      \}\n\n      int max = possSusps.size();\n      int index = (int)(max*Math.random());\n      return (String)possSusps.elementAt(index);\n   \}\n\n   private String getARandInnoWeap()   \{\n      Vector possWeaps = new Vector();\n      if (dpRope == false)      \{\n         possWeaps.add(\"Rope\");\n      \}\n\n      if (dpDagger == false)      \{\n         possWeaps.add(\"Dagger\");\n      \}\n\n      if (dpSpanner == false)      \{\n         possWeaps.add(\"Spanner\");\n      \}\n\n      if (dpRevolver == false)      \{\n         possWeaps.add(\"Revolver\");\n      \}\n\n      if (dpLeadPipe == false)      \{\n         possWeaps.add(\"LeadPipe\");\n      \}\n\n      if (dpCandlestick == false)      \{\n         possWeaps.add(\"Candlestick\");\n      \}\n\n      int max = possWeaps.size();\n      int index = (int)(max*Math.random());\n      return (String)possWeaps.elementAt(index);\n   \}\n\n   private String getARandInnoRoom()   \{\n      Vector possRooms = new Vector();\n      if (dpHall == false)      \{\n         possRooms.add(\"Hall\");\n      \}\n\n      if (dpConservatory == false)      \{\n         possRooms.add(\"Conservatory\");\n      \}\n\n      if (dpStudy == false)      \{\n         possRooms.add(\"Study\");\n      \}\n\n      if (dpBilliardRoom == false)      \{\n         possRooms.add(\"BilliardRoom\");\n      \}\n\n      if (dpLibrary == false)      \{\n         possRooms.add(\"Library\");\n      \}\n\n      if (dpBallroom == false)      \{\n         possRooms.add(\"Ballroom\");\n      \}\n\n      if (dpLounge == false)      \{\n         possRooms.add(\"Lounge\");\n      \}\n\n      if (dpKitchen == false)      \{\n         possRooms.add(\"Kitchen\");\n      \}\n\n      if (dpDiningRoom == false)      \{\n         possRooms.add(\"DiningRoom\");\n      \}\n\n      int max = possRooms.size();\n      int index = (int)(max*Math.random());\n      return (String)possRooms.elementAt(index);\n   \}\n\n\}\n\n";
	// Reset the final code ================================================================================
    
    
    // Insert comments for each code. ======================================================================
    codeEvent1 = "// ==================== START: GAMESTARTED ====================\n";
    for (i in [0..500])
    {        
        if (codeGameStarted[i] != "")
        {
            codeEvent1 = "{codeEvent1}{codeGameStarted[i]}";
        }
    }
    codeEvent1 = "{codeEvent1}// ==================== END: GAMESTARTED ====================\n";   
    
    
    
    
    
    
    codeEvent2 = "// ==================== START: DECIDINGONMOVEMENT ====================\n";
    codeEvent2 = "{codeEvent2}   private void runDecideOnMovementEvent()\{\n";
    codeEvent2 = "{codeEvent2}      outputMessage(\"EVENT:  Assuming I'm allowed... should I suggest, accuse or both?\");\n";
    codeEvent2 = "{codeEvent2}      // ===== START CODE INJECT ====\n";
    for (i in [0..500])
    {
        if (codeDecidingOnMovement[i] != "")
        {
            codeEvent2 = "{codeEvent2}{codeDecidingOnMovement[i]}";
        }
    }
    codeEvent2 = "{codeEvent2}   // ===== END CODE INJECT ====\n";
    codeEvent2 = "{codeEvent2}   \}\n\n";
    codeEvent2 = "{codeEvent2}// ==================== END: DECIDINGONMOVEMENT ====================\n\n";
    
   	
    
    
    
    
    
    
    codeEvent3 = "// ==================== START: DECIDINGONSUGGESTANDACCUSE ====================\n";
    codeEvent3 = "{codeEvent3}   private void runSuggestOrAccuseEvent()\{\n";
    codeEvent3 = "{codeEvent3}      outputMessage(\"EVENT:  I have to disprove the suggestion.\");\n";
    codeEvent3 = "{codeEvent3}      Player me = gameController.getBoard().getPlayer(myName);\n";
    //codeEvent3 = "{codeEvent3}      if (me.canSuggestHere() == true && me.canSuggest() == true)\{\n";
    codeEvent3 = "{codeEvent3}      // ===== START CODE INJECT =====\n";
    for (i in [0..500])
    {   
        if (codeMakingASuggestionOrAccusation[i] != "")
        {
            codeEvent3 = "{codeEvent3}         {codeMakingASuggestionOrAccusation[i]}";
        }
    }
    codeEvent3 = "{codeEvent3}      // ===== END CODE INJECT =====\n";
    //codeEvent3 = "{codeEvent3}      \}\n";
    codeEvent3 = "{codeEvent3}   \}\n";
    codeEvent3 = "{codeEvent3}// ==================== END: DECIDINGONSUGGESTANDACCUSE ====================\n\n";
    
    
    
    
    
    
        
    codeEvent4 = "// ==================== START: DISPROVESUGGESTION ====================\n";
    codeEvent4 = "{codeEvent4}   private void handleSuggestionAlert(Message message)\n\{";
    codeEvent4 = "{codeEvent4}      outputMessage(\"EVENT:  I have to disprove the suggestion.\");\n";
    codeEvent4 = "{codeEvent4}      Message disproofAlert = new Message();\n";
    codeEvent4 = "{codeEvent4}      String chosenCard = \"\";\n\n";
    codeEvent4 = "{codeEvent4}      disproofAlert.type = \"disproofAlert\";\n\n";
    codeEvent4 = "{codeEvent4}      SuggestionAlert alert = (SuggestionAlert)message.parameters.elementAt(0);\n";
    codeEvent4 = "{codeEvent4}      Player me = gameController.getBoard().getPlayer(myName);\n\n";
    codeEvent4 = "{codeEvent4}      suggestedSuspect = alert.getWho().getName();\n";
    codeEvent4 = "{codeEvent4}      suggestedWeapon  = alert.getWhat().getName();\n";
    codeEvent4 = "{codeEvent4}      suggestedRoom    = alert.getWhere().getName();\n\n";
    codeEvent4 = "{codeEvent4}      outputMessage(\"I have to disprove this suggestion: \" + suggestedSuspect + \", \" + suggestedWeapon + \" and \" + suggestedRoom +\" ...\");\n";
    codeEvent4 = "{codeEvent4}      if (!hasDisproved)\{\n";
    codeEvent4 = "{codeEvent4}      //======= START CODE INJECT ======\n";
    for (i in [0..500])
    {
        if (codeDisprovingSuggestion[i] != "")
        {
            codeEvent4 = "{codeEvent4}{codeDisprovingSuggestion[i]}";
        }
    }
    codeEvent4 = "{codeEvent4}      //======= END CODE INJECT ======\n";
    codeEvent4 = "{codeEvent4}      \}\n";
    codeEvent4 = "{codeEvent4}      disproofAlert.parameters.add(new DisproofAlert( chosenCard, alert, myName ));\n";
    codeEvent4 = "{codeEvent4}      gameController.relayMessage(disproofAlert);\n";
    codeEvent4 = "{codeEvent4}      if (chosenCard.equals(\"\"))\{\n";
    codeEvent4 = "{codeEvent4}           outputMessage(\"I could not disprove the suggestion because I don't have a right card.\");\n";
    codeEvent4 = "{codeEvent4}        \}\n\nelse\{\n";
    codeEvent4 = "{codeEvent4}           outputMessage(\"I disproved the suggestion using \" + chosenCard + \".\");\n";
    codeEvent4 = "{codeEvent4}        \}\n\n";
    codeEvent4 = "{codeEvent4}   \}";
    codeEvent4 = "{codeEvent4}// ==================== END: DISPROVESUGGESTION ====================\n";
    
    
    
    codeEvent5 = "// ==================== START: LISTENTOSUGGESTION ====================\n";
    codeEvent5 = "{codeEvent5}   private void deductFromDisproof(DisproofAlert d) \{\n";
    codeEvent5 = "{codeEvent5}      outputMessage(\"EVENT:  I should probably listen to what others are suggesting, and possibly disproving.\");\n";
	codeEvent5 = "{codeEvent5}      if (!d.getOriginalSuggestion().suggestedBy.equals(\"\"))\{\n";
	codeEvent5 = "{codeEvent5}         outputMessage(\"No one could disprove the suggestion of \" + d.getDisprovedBy() + \".\");\n";
	codeEvent5 = "{codeEvent5}      \}\n\nelse\{\n";
	codeEvent5 = "{codeEvent5}         outputMessage(\"The suggestion of \" + d.getDisprovedBy() + \" was disproved by \" + d.getDisprovedBy() + \" ...\");\n";
	codeEvent5 = "{codeEvent5}      \}\n\n";
    codeEvent5 = "{codeEvent5}      // ===== START CODE INJECT =====\n";
    for (i in [0..500])
    {
        if (codeListeningToSuggestion[i] != "")
        {
            codeEvent5 = "{codeEvent5}{codeListeningToSuggestion[i]}";
        }
    }
    codeEvent5 = "{codeEvent5}      // ===== END CODE INJECT =====\n";
    codeEvent5 = "{codeEvent5}   \}";
    codeEvent5 = "{codeEvent5}// ==================== END: LISTENTOSUGGESTION ====================\n";	
    
    codeAI = "{code1}{codeEvent1}{code2}{code3}{code4}{code5}{code6}{codeEvent2}{codeEvent3}{codeEvent4}{codeEvent5}{code7}{codeCanReach}{codeHaveSug}{codeHaveCard}{codeRoomFuncs}{codeIElim}{codeGetARandInno}";    
}